Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix UnicodeDecodeError occuring diff.py::split_by_sep() #18529

Merged
merged 1 commit into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions w3af/core/controllers/misc/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def chunked_diff(a, b):
return ''.join(a_chunks), ''.join(b_chunks)


def split_by_sep(seq):
def split_by_sep(sequence):
"""
This method will split the HTTP response body by various separators,
such as new lines, tabs, <, double and single quotes.
Expand Down Expand Up @@ -178,7 +178,7 @@ def split_by_sep(seq):
chunks without much meaning and reduce the performance improvement we
have achieved.

:param seq: A string
:param sequence: A string which we will split
:return: A list of strings (chunks) for the input string
"""
#
Expand All @@ -195,5 +195,8 @@ def split_by_sep(seq):
#
# [0] https://github.com/andresriancho/w3af/blob/2ded693c959c91dc3e4daca276460d6c64ada479/w3af/core/controllers/misc/diff.py#L173
#
translated_seq = string.translate(seq, TRANSLATION_TABLE)
try:
translated_seq = string.translate(sequence, TRANSLATION_TABLE)
except UnicodeDecodeError:
translated_seq = string.translate(sequence.encode('utf-8'), TRANSLATION_TABLE)
return translated_seq.split('\0')
5 changes: 5 additions & 0 deletions w3af/core/controllers/misc/tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ def test_split_by_sep_2(self):
result = split_by_sep('hello world<bye\nbye!')
self.assertEqual(result, ['hello world', 'bye', 'bye!'])

def test_split_by_sep_utf8(self):
sequence = u'ąęż'
# this shouldn't rise UnicodeDecodeError
split_by_sep(sequence)

def test_split_by_sep_perf(self):
loops = 1000
inputs = [unittest.__doc__,
Expand Down