diff options
author | Thomas Kriechbaumer <Kriechi@users.noreply.github.com> | 2016-08-26 10:54:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-26 10:54:08 +0200 |
commit | af0a58256a19dec697fa5c62cd92189407656ab3 (patch) | |
tree | 7b21ae5e85324a1ffcf280f7a71f344532949bc5 | |
parent | 51771c01c61259d8cc62ff8cc9715dced9806354 (diff) | |
parent | 2cf4efab0793fc299781bed531cd88cb17110060 (diff) | |
download | mitmproxy-af0a58256a19dec697fa5c62cd92189407656ab3.tar.gz mitmproxy-af0a58256a19dec697fa5c62cd92189407656ab3.tar.bz2 mitmproxy-af0a58256a19dec697fa5c62cd92189407656ab3.zip |
Merge pull request #1510 from mkagenius/dividebyzero
fixed #1501 : Divide by zero error came when string was empty, also a test
-rw-r--r-- | netlib/strutils.py | 3 | ||||
-rw-r--r-- | test/netlib/test_strutils.py | 1 |
2 files changed, 4 insertions, 0 deletions
diff --git a/netlib/strutils.py b/netlib/strutils.py index 4a46b6b1..4cb3b805 100644 --- a/netlib/strutils.py +++ b/netlib/strutils.py @@ -121,6 +121,9 @@ def escaped_str_to_bytes(data): def is_mostly_bin(s): # type: (bytes) -> bool + if not s or len(s) == 0: + return False + return sum( i < 9 or 13 < i < 32 or 126 < i for i in six.iterbytes(s[:100]) diff --git a/test/netlib/test_strutils.py b/test/netlib/test_strutils.py index 52299e59..5be254a3 100644 --- a/test/netlib/test_strutils.py +++ b/test/netlib/test_strutils.py @@ -85,6 +85,7 @@ def test_escaped_str_to_bytes(): def test_is_mostly_bin(): assert not strutils.is_mostly_bin(b"foo\xFF") assert strutils.is_mostly_bin(b"foo" + b"\xFF" * 10) + assert not strutils.is_mostly_bin("") def test_is_xml(): |