diff options
author | Joergen Ibsen <ji@ibse.dk> | 2017-11-24 14:43:23 +0100 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2017-11-27 21:23:32 +0200 |
commit | b9a0589067a532c7a508f8f3526d3d019e3ae633 (patch) | |
tree | f8e922ca1d85bf58505cb14a429b98e5f5ada3d5 /mesonbuild/mparser.py | |
parent | da2343fb5e5fcb6a1c6bb7b3f6ae24b3ed50ca9d (diff) | |
download | meson-b9a0589067a532c7a508f8f3526d3d019e3ae633.zip meson-b9a0589067a532c7a508f8f3526d3d019e3ae633.tar.gz meson-b9a0589067a532c7a508f8f3526d3d019e3ae633.tar.bz2 |
Fix escaping of newlines in string literals
Replace '\n' escape sequence before '\\' to allow a literal backslash
to be inserted before the character 'n'.
Fixes #2682
Diffstat (limited to 'mesonbuild/mparser.py')
-rw-r--r-- | mesonbuild/mparser.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py index 8400a1a..0465d24 100644 --- a/mesonbuild/mparser.py +++ b/mesonbuild/mparser.py @@ -111,6 +111,7 @@ class Lexer: par_count = 0 bracket_count = 0 col = 0 + newline_rx = re.compile(r'(?<!\\)((?:\\\\)*)\\n') while loc < len(self.code): matched = False value = None @@ -139,10 +140,9 @@ class Lexer: elif tid == 'dblquote': raise ParseException('Double quotes are not supported. Use single quotes.', self.getline(line_start), lineno, col) elif tid == 'string': - value = match_text[1:-1]\ - .replace(r"\'", "'")\ - .replace(r" \\ ".strip(), r" \ ".strip())\ - .replace("\\n", "\n") + value = match_text[1:-1].replace(r"\'", "'") + value = newline_rx.sub(r'\1\n', value) + value = value.replace(r" \\ ".strip(), r" \ ".strip()) elif tid == 'multiline_string': tid = 'string' value = match_text[3:-3] |