From e1af76e71f6b2230847767c0bbccdc40fd98bb3b Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 26 Aug 2017 17:04:56 +0200 Subject: [PATCH] fix strutils.split_special_areas --- mitmproxy/utils/strutils.py | 4 ++-- test/mitmproxy/utils/test_strutils.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mitmproxy/utils/strutils.py b/mitmproxy/utils/strutils.py index 1a4b5bb20..37bed7ded 100644 --- a/mitmproxy/utils/strutils.py +++ b/mitmproxy/utils/strutils.py @@ -172,14 +172,14 @@ def split_special_areas( "".join(split_special_areas(x, ...)) == x always holds true. """ patterns = "|".join( - r"{lchar}.*?{rchar}".format( + r"{lchar}[\s\S]*?{rchar}".format( lchar=a, rchar=b, ) for (a, b) in area_delimiter) return re.split( "({})".format(patterns), data, - re.MULTILINE + flags=re.MULTILINE ) diff --git a/test/mitmproxy/utils/test_strutils.py b/test/mitmproxy/utils/test_strutils.py index ea3569c03..7ec72e4ec 100644 --- a/test/mitmproxy/utils/test_strutils.py +++ b/test/mitmproxy/utils/test_strutils.py @@ -111,6 +111,14 @@ def test_split_special_areas(): """foo 'b\\'a"r' baz""", ESCAPE_QUOTES ) == ["foo ", "'b\\'a\"r'", " baz"] + assert strutils.split_special_areas( + "foo\n/*bar\nbaz*/\nqux", + [(r'/\*', r'\*/')] + ) == ["foo\n", "/*bar\nbaz*/", "\nqux"] + assert strutils.split_special_areas( + "foo\n//bar\nbaz", + [(r'//', r'$')] + ) == ["foo\n", "//bar", "\nbaz"] def test_escape_special_areas():