Skip to content

Commit d151e42

Browse files
committed
fixup! Preserve attribute order when parsing
Add a parser test for duplicate attributes; fix.
1 parent e847f22 commit d151e42

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

html5lib/html5parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def normalizeToken(self, token):
265265
""" HTML5 specific normalizations to the token stream """
266266

267267
if token["type"] == tokenTypes["StartTag"]:
268-
token["data"] = OrderedDict(token['data'])
268+
token["data"] = OrderedDict(token['data'][::-1])
269269

270270
return token
271271

html5lib/tests/test_parser2.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ def test_unicode_file(self):
5151
parser = html5parser.HTMLParser()
5252
parser.parse(io.StringIO("a"))
5353

54+
def test_duplicateAttribute(self):
55+
# This is here because we impl it in parser and not tokenizer
56+
parser = html5parser.HTMLParser()
57+
doc = parser.parse('<p class=a class=b>')
58+
el = doc[1][0]
59+
self.assertEqual(el.get("class"), "a")
60+
5461

5562
def buildTestSuite():
5663
return unittest.defaultTestLoader.loadTestsFromName(__name__)

0 commit comments

Comments
 (0)