浏览代码

Fix behavior with quoted attrs and spaces before the =.

tags/v0.3
Ben Kurtovic 11 年前
父节点
当前提交
9280cb16fe
共有 2 个文件被更改,包括 7 次插入4 次删除
  1. +5
    -4
      mwparserfromhell/nodes/extras/attribute.py
  2. +2
    -0
      tests/test_attribute.py

+ 5
- 4
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."""


+ 2
- 0
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, " ", "", " ")


正在加载...
取消
保存