From 7a4b1625d3fd115a1206bd4db7dc95ccc50a26cd Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Fri, 2 Aug 2013 22:41:36 -0400 Subject: [PATCH] Strip self-closing tags correctly. --- mwparserfromhell/nodes/tag.py | 2 +- tests/test_tag.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mwparserfromhell/nodes/tag.py b/mwparserfromhell/nodes/tag.py index 08d5204..d63af02 100644 --- a/mwparserfromhell/nodes/tag.py +++ b/mwparserfromhell/nodes/tag.py @@ -89,7 +89,7 @@ class Tag(Node): yield self.closing_tag, child def __strip__(self, normalize, collapse): - if is_visible(self.tag): + if self.contents and is_visible(self.tag): return self.contents.strip_code(normalize, collapse) return None diff --git a/tests/test_tag.py b/tests/test_tag.py index 6755270..a7a4b4a 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -102,10 +102,12 @@ class TestTag(TreeEqualityTestCase): """test Tag.__strip__()""" node1 = Tag(wraptext("i"), wraptext("foobar")) node2 = Tag(wraptext("math"), wraptext("foobar")) + node3 = Tag(wraptext("br"), self_closing=True) for a in (True, False): for b in (True, False): self.assertEqual("foobar", node1.__strip__(a, b)) self.assertEqual(None, node2.__strip__(a, b)) + self.assertEqual(None, node3.__strip__(a, b)) def test_showtree(self): """test Tag.__showtree__()"""