summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mdbp/sbuild.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/mdbp/sbuild.py b/mdbp/sbuild.py
index f1d4fe4..2841713 100644
--- a/mdbp/sbuild.py
+++ b/mdbp/sbuild.py
@@ -16,6 +16,10 @@ from .common import AddSpaceSeparatedValues, buildjson, clean_dir, \
PerlValue = typing.Union[None, str, typing.List[typing.Any],
typing.Dict[str, typing.Any]]
+perl_escape_map = {
+ ord("\\"): r"\\", ord('"'): r'\"', ord("@"): r"\@", ord("$"): r"\$",
+ ord("\n"): r"\n", ord("\r"): r"\r",
+}
def perl_repr(value: PerlValue) -> str:
"""Encode a Python value as a string parseable to Perl."""
if value is None:
@@ -23,11 +27,7 @@ def perl_repr(value: PerlValue) -> str:
if isinstance(value, bool):
return str(int(value))
if isinstance(value, str):
- return '"%s"' % value \
- .replace("\\", r"\\") \
- .replace('"', r'\"') \
- .replace("\n", r"\n") \
- .replace("\r", r"\r")
+ return '"%s"' % value.translate(perl_escape_map)
if isinstance(value, list):
return "[%s]" % ",".join(map(perl_repr, value))
if isinstance(value, dict):