aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-07-30 15:56:55 -0700
committerGitHub <noreply@github.com>2016-07-30 15:56:55 -0700
commitca2e33887610c7a25b35d93808248d0a98030acc (patch)
treed79c9d2919ff1acf21ee8b79eb6a992d1be96bef /netlib
parentf008bdf5901563923d25c1bba4109efba8d444f3 (diff)
parent453436367103dd9deb693da5b5ebb18c2c2c86ce (diff)
downloadmitmproxy-ca2e33887610c7a25b35d93808248d0a98030acc.tar.gz
mitmproxy-ca2e33887610c7a25b35d93808248d0a98030acc.tar.bz2
mitmproxy-ca2e33887610c7a25b35d93808248d0a98030acc.zip
Merge pull request #1449 from mhils/fix-1448
Add escape_single_quotes=False arg to bytes_to_escaped_str
Diffstat (limited to 'netlib')
-rw-r--r--netlib/strutils.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/netlib/strutils.py b/netlib/strutils.py
index 8f27ebb7..4a46b6b1 100644
--- a/netlib/strutils.py
+++ b/netlib/strutils.py
@@ -69,7 +69,7 @@ def escape_control_characters(text, keep_spacing=True):
return text.translate(trans)
-def bytes_to_escaped_str(data, keep_spacing=False):
+def bytes_to_escaped_str(data, keep_spacing=False, escape_single_quotes=False):
"""
Take bytes and return a safe string that can be displayed to the user.
@@ -86,6 +86,8 @@ def bytes_to_escaped_str(data, keep_spacing=False):
# We always insert a double-quote here so that we get a single-quoted string back
# https://stackoverflow.com/questions/29019340/why-does-python-use-different-quotes-for-representing-strings-depending-on-their
ret = repr(b'"' + data).lstrip("b")[2:-1]
+ if not escape_single_quotes:
+ ret = re.sub(r"(?<!\\)(\\\\)*\\'", lambda m: (m.group(1) or "") + "'", ret)
if keep_spacing:
ret = re.sub(
r"(?<!\\)(\\\\)*\\([nrt])",