Skip to content

Commit aee4815

Browse files
committed
Fix output html missing no-value attributes (like 'checked' attribute)
1 parent 9ee4d6d commit aee4815

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

AdvancedHTMLParser/Tags.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ def getStartTag(self):
531531
if val:
532532
val = val.replace('"', '\\"')
533533
attributeString.append('%s="%s"' %(name, val) )
534+
else:
535+
attributeString.append(name)
534536

535537
if attributeString:
536538
attributeString = ' ' + ' '.join(attributeString)

tests/AdvancedHTMLParserTests/test_Attributes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,14 @@ def test_classNames(self):
105105
assert 'def' in tag.outerHTML , ' Failed to retain in outerHTML'
106106

107107

108+
def test_noValueAttributes(self):
109+
parser = AdvancedHTMLParser()
110+
parser.parseStr('<input id="thebox" type="checkbox" checked />')
111+
112+
tag = parser.getElementById('thebox')
113+
assert 'checked' in tag.attributes
114+
assert 'checked' in tag.outerHTML
115+
116+
108117
if __name__ == '__main__':
109118
pipe = subprocess.Popen('GoodTests.py "%s"' %(sys.argv[0],), shell=True).wait()

0 commit comments

Comments
 (0)