From 45caaa4d8a978d971789cd0dae13b8f8584ec814 Mon Sep 17 00:00:00 2001 From: Nate Choe Date: Mon, 6 Jun 2022 17:06:13 -0500 Subject: [PATCH] Added escaping escape characters --- src/parse.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/parse.c b/src/parse.c index ed286ef..0e767e5 100644 --- a/src/parse.c +++ b/src/parse.c @@ -104,8 +104,7 @@ static int writefile(struct expandfile *file, FILE *out) { break; } case AUTOESCAPE_CHAR: - for (++i; data->data[i] != ESCAPE_CHAR && - i < data->len; ++i) { + for (++i; i < data->len; ++i) { switch (data->data[i]) { case '&': fputs("&", out); @@ -118,16 +117,27 @@ static int writefile(struct expandfile *file, FILE *out) { case '>': fputs(">", out); break; + case ESCAPE_CHAR: + if (data->data[i + 1] != ESCAPE_CHAR) + goto autoescapeend; + ++i; + /* fallthrough */ default: fputc(data->data[i], out); break; } } +autoescapeend: break; case NOMINIFY_CHAR: - for (++i; data->data[i] != ESCAPE_CHAR && - i < data->len; ++i) + for (++i; data->data[i] != ESCAPE_CHAR && i < data->len; ++i) { + if (data->data[i] == ESCAPE_CHAR) { + if (data->data[i + 1] != ESCAPE_CHAR) + break; + ++i; + } fputc(data->data[i], out); + } break; } }