From a798cf2f2119409addbc395ead1d84902495f1e3 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Fri, 6 Jul 2018 14:37:18 +0200 Subject: [PATCH 1/2] buxfix: in regsub continue scanning only after last substitution --- src/RegexpConverter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RegexpConverter.cc b/src/RegexpConverter.cc index 693ffd3..542a978 100644 --- a/src/RegexpConverter.cc +++ b/src/RegexpConverter.cc @@ -223,7 +223,7 @@ static void regsubst(const StreamFormat& fmt, StreamBuffer& buffer, long start) } buffer.replace(start+c+ovector[0], l, s); length += s.length() - l; - c += s.length(); + c += ovector[0] + s.length(); if (n == fmt.prec) // max match reached return; } From 343eef324b2bb94909aabf7bc3665f109b851ee7 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Fri, 6 Jul 2018 16:48:15 +0200 Subject: [PATCH 2/2] bugfix: in quoted strings do not mis-interpret double backslash before quote or $ as escape char --- src/StreamProtocol.cc | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/StreamProtocol.cc b/src/StreamProtocol.cc index 6f97db8..5fde7af 100644 --- a/src/StreamProtocol.cc +++ b/src/StreamProtocol.cc @@ -512,20 +512,31 @@ Each time newline is read, line is incremented. buffer(token)); return false; } - if (c == '$' && buffer[-1] == '\\') - { - // quoted variable reference - // terminate string here and do variable in next pass - buffer[-1] = quote; - ungetc(c, file); - break; - } buffer.append(c); - if (c == quote && buffer[-2] != '\\') + if (c == quote) { quote = false; break; } + if (c == '\\') + { + c = getc(file); + if (c == '$') + { + // quoted variable reference + // terminate string here and do variable in next pass + buffer[-1] = quote; + ungetc(c, file); + break; + } + if (c == EOF || c == '\n') + { + error(line, filename(), "Backslash at end of line: %s\n", + buffer(token)); + return false; + } + buffer.append(c); + } c = getc(file); } buffer.append('\0').append(&l, sizeof(l)); // append line number