diff options
author | Volker Weißmann <volker.weissmann@gmx.de> | 2022-09-04 12:16:14 +0200 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2022-09-07 08:56:51 -0400 |
commit | 5fec9f5db9f9bc56577a7a76b32fd49ebe36800b (patch) | |
tree | 2d1629edcb4582366e502cb4dc00af8446802ac8 /mesonbuild | |
parent | 26acf2152dd8c56f2eadc4d6a8bfc6cb86c62981 (diff) | |
download | meson-5fec9f5db9f9bc56577a7a76b32fd49ebe36800b.zip meson-5fec9f5db9f9bc56577a7a76b32fd49ebe36800b.tar.gz meson-5fec9f5db9f9bc56577a7a76b32fd49ebe36800b.tar.bz2 |
Fixed string escaping in AstPrinter
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/ast/printer.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/mesonbuild/ast/printer.py b/mesonbuild/ast/printer.py index a0b92bb..b095f53 100644 --- a/mesonbuild/ast/printer.py +++ b/mesonbuild/ast/printer.py @@ -72,9 +72,13 @@ class AstPrinter(AstVisitor): self.append(str(node.value), node) node.lineno = self.curr_line or node.lineno + def escape(self, val: str) -> str: + return val.translate(str.maketrans({'\'': '\\\'', + '\\': '\\\\'})) + def visit_StringNode(self, node: mparser.StringNode) -> None: assert isinstance(node.value, str) - self.append("'" + node.value + "'", node) + self.append("'" + self.escape(node.value) + "'", node) node.lineno = self.curr_line or node.lineno def visit_FormatStringNode(self, node: mparser.FormatStringNode) -> None: |