aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-06-06 13:31:44 -0700
committerMaximilian Hils <git@maximilianhils.com>2016-06-06 13:31:44 -0700
commit6447c8ae2256b0e074a04307a748d61f990e98d4 (patch)
tree4a8a236e0ed93cb681b701c55778e4ab93e0eaab
parentc973fd881fc4cabb401fdb255b2486b80499442c (diff)
downloadmitmproxy-6447c8ae2256b0e074a04307a748d61f990e98d4.tar.gz
mitmproxy-6447c8ae2256b0e074a04307a748d61f990e98d4.tar.bz2
mitmproxy-6447c8ae2256b0e074a04307a748d61f990e98d4.zip
fix .freeze(), improve tests
-rw-r--r--pathod/language/base.py2
-rw-r--r--test/pathod/test_language_base.py11
-rw-r--r--test/pathod/test_language_http.py4
3 files changed, 11 insertions, 6 deletions
diff --git a/pathod/language/base.py b/pathod/language/base.py
index bc389792..6cafdebd 100644
--- a/pathod/language/base.py
+++ b/pathod/language/base.py
@@ -578,4 +578,4 @@ class NestedMessage(Token):
def freeze(self, settings):
f = self.parsed.freeze(settings).spec()
- return self.__class__(TokValueLiteral(strutils.bytes_to_escaped_str(f)))
+ return self.__class__(TokValueLiteral(strutils.bytes_to_escaped_str(f.encode())))
diff --git a/test/pathod/test_language_base.py b/test/pathod/test_language_base.py
index bb1e864b..7c7d8cf9 100644
--- a/test/pathod/test_language_base.py
+++ b/test/pathod/test_language_base.py
@@ -55,8 +55,15 @@ class TestTokValueLiteral:
v = base.TokValueLiteral("f\x00oo")
assert v.spec() == repr(v) == r"'f\x00oo'"
- v = base.TokValueLiteral("\"")
- assert v.spec() == repr(v) == '\'"\''
+ v = base.TokValueLiteral('"')
+ assert v.spec() == repr(v) == """ '"' """.strip()
+
+ # While pyparsing has a escChar argument for QuotedString,
+ # escChar only performs scapes single-character escapes and does not work for e.g. r"\x02".
+ # Thus, we cannot use that option, which means we cannot have single quotes in strings.
+ # To fix this, we represent single quotes as r"\x07".
+ v = base.TokValueLiteral("'")
+ assert v.spec() == r"'\x27'"
def roundtrip(self, spec):
e = base.TokValueLiteral.expr()
diff --git a/test/pathod/test_language_http.py b/test/pathod/test_language_http.py
index 20809fcf..0ef1e109 100644
--- a/test/pathod/test_language_http.py
+++ b/test/pathod/test_language_http.py
@@ -340,9 +340,7 @@ def test_nested_response():
def test_nested_response_freeze():
e = http.NestedResponse(
base.TokValueLiteral(
- "200:b'foo':i10,'\\x27'".encode(
- "string_escape"
- )
+ r"200:b\'foo\':i10,\'\\x27\'"
)
)
assert e.freeze({})