From 9280cb16feee70760561033c640f49fafaa062ee Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Mon, 19 Aug 2013 22:21:45 -0400 Subject: [PATCH] Fix behavior with quoted attrs and spaces before the =. --- mwparserfromhell/nodes/extras/attribute.py | 9 +++++---- tests/test_attribute.py | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mwparserfromhell/nodes/extras/attribute.py b/mwparserfromhell/nodes/extras/attribute.py index 05860a0..8f7f453 100644 --- a/mwparserfromhell/nodes/extras/attribute.py +++ b/mwparserfromhell/nodes/extras/attribute.py @@ -47,12 +47,13 @@ class Attribute(StringMixIn): self._pad_after_eq = pad_after_eq def __unicode__(self): - base = self.pad_first + str(self.name) + self.pad_before_eq + result = self.pad_first + str(self.name) + self.pad_before_eq if self.value is not None: + result += "=" + self.pad_after_eq if self.quoted: - return base + '="' + self.pad_after_eq + str(self.value) + '"' - return base + "=" + self.pad_after_eq + str(self.value) - return base + return result + '"' + str(self.value) + '"' + return result + str(self.value) + return result def _set_padding(self, attr, value): """Setter for the value of a padding attribute.""" diff --git a/tests/test_attribute.py b/tests/test_attribute.py index dbf3145..f34c670 100644 --- a/tests/test_attribute.py +++ b/tests/test_attribute.py @@ -38,6 +38,8 @@ class TestAttribute(TreeEqualityTestCase): self.assertEqual(" foo", str(node)) node2 = Attribute(wraptext("foo"), wraptext("bar")) self.assertEqual(' foo="bar"', str(node2)) + node3 = Attribute(wraptext("a"), wraptext("b"), True, "", " ", " ") + self.assertEqual('a = "b"', str(node3)) node3 = Attribute(wraptext("a"), wraptext("b"), False, "", " ", " ") self.assertEqual("a = b", str(node3)) node4 = Attribute(wraptext("a"), wrap([]), False, " ", "", " ")