diff options
-rw-r--r-- | libmproxy/utils.py | 16 | ||||
-rw-r--r-- | test/test_utils.py | 5 |
2 files changed, 12 insertions, 9 deletions
diff --git a/libmproxy/utils.py b/libmproxy/utils.py index 2a878676..e29910c5 100644 --- a/libmproxy/utils.py +++ b/libmproxy/utils.py @@ -52,13 +52,10 @@ TAG = r""" (?P<close>\s*\/)? (?P<name>\w+) ( - [a-zA-Z0-9_#:=().%\/]+ - | - "[^\"]*"['\"]* - | - '[^']*'['\"]* - | - \s+ + [^'"\t >]+ | + "[^\"]*"['\"]* | + '[^']*'['\"]* | + \s+ )* (?P<selfcont>\s*\/\s*)? \s*> @@ -67,7 +64,7 @@ UNI = set(["br", "hr", "img", "input", "area", "link"]) INDENT = " "*4 def pretty_xmlish(s): """ - This is a robust, general pretty-printer for XML-ish data. + A robust pretty-printer for XML-ish data. Returns a list of lines. """ data, offset, indent, prev = [], 0, 0, None @@ -87,6 +84,9 @@ def pretty_xmlish(s): if not any([i.group("close"), i.group("selfcont"), name in UNI]): indent += 1 prev = name + trail = s[offset:] + if trail.strip(): + data.append(s[offset:]) return data diff --git a/test/test_utils.py b/test/test_utils.py index 1ec4f2f5..5cf81e2e 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -242,6 +242,9 @@ class upretty_xmlish(libpry.AutoTree): assert f(r"<foo a='b\"'>") assert f(r'<a b=(a.b) href="foo">') assert f('<td width=25%>') + assert f('<form name="search" action="/search.php" method="get" accept-charset="utf-8" class="search">') + assert f('<img src="gif" width="125" height="16" alt="" />') + def test_all(self): def isbalanced(ret): @@ -278,7 +281,7 @@ class upretty_xmlish(libpry.AutoTree): isbalanced(ret) s = "gobbledygook" - print utils.pretty_xmlish(s) + assert utils.pretty_xmlish(s) == ["gobbledygook"] |