diff options
author | Helmut Grohne <helmut@subdivi.de> | 2021-07-01 15:11:04 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2021-07-01 15:11:04 +0200 |
commit | 2e9f3bddc0c9c7fd3411a2e41f49d048c93ba52e (patch) | |
tree | 37ca770db04ff5d64bc8d900139ea17399eb28da /mdbp/sbuild.py | |
parent | 7920b4d691444a5b6ae650e7bd62bcecd6daef08 (diff) | |
download | mdbp-2e9f3bddc0c9c7fd3411a2e41f49d048c93ba52e.tar.gz |
sbuild: fix quoting of config strings
Not escaping a $ would make perl interpolate it at config parsing time.
Fixes: 8ea45852d692 ("sbuild: make environment passing work")
Diffstat (limited to 'mdbp/sbuild.py')
-rw-r--r-- | mdbp/sbuild.py | 10 |
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): |