mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
fix .freeze(), improve tests
This commit is contained in:
parent
c973fd881f
commit
6447c8ae22
@ -578,4 +578,4 @@ class NestedMessage(Token):
|
|||||||
|
|
||||||
def freeze(self, settings):
|
def freeze(self, settings):
|
||||||
f = self.parsed.freeze(settings).spec()
|
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())))
|
||||||
|
@ -55,8 +55,15 @@ class TestTokValueLiteral:
|
|||||||
v = base.TokValueLiteral("f\x00oo")
|
v = base.TokValueLiteral("f\x00oo")
|
||||||
assert v.spec() == repr(v) == r"'f\x00oo'"
|
assert v.spec() == repr(v) == r"'f\x00oo'"
|
||||||
|
|
||||||
v = base.TokValueLiteral("\"")
|
v = base.TokValueLiteral('"')
|
||||||
assert v.spec() == repr(v) == '\'"\''
|
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):
|
def roundtrip(self, spec):
|
||||||
e = base.TokValueLiteral.expr()
|
e = base.TokValueLiteral.expr()
|
||||||
|
@ -340,9 +340,7 @@ def test_nested_response():
|
|||||||
def test_nested_response_freeze():
|
def test_nested_response_freeze():
|
||||||
e = http.NestedResponse(
|
e = http.NestedResponse(
|
||||||
base.TokValueLiteral(
|
base.TokValueLiteral(
|
||||||
"200:b'foo':i10,'\\x27'".encode(
|
r"200:b\'foo\':i10,\'\\x27\'"
|
||||||
"string_escape"
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
assert e.freeze({})
|
assert e.freeze({})
|
||||||
|
Loading…
Reference in New Issue
Block a user