aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod/language.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-10-25 10:59:18 +1300
committerAldo Cortesi <aldo@nullcube.com>2012-10-25 10:59:18 +1300
commit6174e46023e798517ac206b7681dd9c7d36b1283 (patch)
tree77909d09a82834be448903d7d0ef97de5439f0a4 /libpathod/language.py
parent173b5c596e72700544f0252040adf3cbe8ebcb50 (diff)
downloadmitmproxy-6174e46023e798517ac206b7681dd9c7d36b1283.tar.gz
mitmproxy-6174e46023e798517ac206b7681dd9c7d36b1283.tar.bz2
mitmproxy-6174e46023e798517ac206b7681dd9c7d36b1283.zip
Unit test suite love: 100% coverage
Also start figuring out how to sanitize binary data in the JSON API.
Diffstat (limited to 'libpathod/language.py')
-rw-r--r--libpathod/language.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/libpathod/language.py b/libpathod/language.py
index c9aa7f66..fa80360b 100644
--- a/libpathod/language.py
+++ b/libpathod/language.py
@@ -428,7 +428,7 @@ class _Action:
def __repr__(self):
return self.spec()
-
+
def accept(self, settings, r):
r.actions.append(self)
@@ -665,6 +665,7 @@ class Message:
# Careful not to log any VALUE specs without sanitizing them first. We truncate at 1k.
if hasattr(v, "__len__"):
v = v[:TRUNCATE]
+ v = v.encode("string_escape")
ret[i] = v
return ret
@@ -815,6 +816,10 @@ def parse_response(settings, s):
"""
May raise ParseException or FileAccessDenied
"""
+ try:
+ s.decode("ascii")
+ except UnicodeError:
+ raise ParseException("Spec must be valid ASCII.", 0, 0)
if s.startswith(FILESTART):
s = read_file(settings, s)
try:
@@ -827,6 +832,10 @@ def parse_request(settings, s):
"""
May raise ParseException or FileAccessDenied
"""
+ try:
+ s.decode("ascii")
+ except UnicodeError:
+ raise ParseException("Spec must be valid ASCII.", 0, 0)
if s.startswith(FILESTART):
s = read_file(settings, s)
try: