diff --git a/src/RegexpConverter.cc b/src/RegexpConverter.cc index 4819768..b7ac056 100644 --- a/src/RegexpConverter.cc +++ b/src/RegexpConverter.cc @@ -230,7 +230,7 @@ static void regsubst(const StreamFormat& fmt, StreamBuffer& buffer, size_t 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; } diff --git a/src/StreamProtocol.cc b/src/StreamProtocol.cc index 6c57e42..165d460 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