Skip to content

Commit 29dbf97

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

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
@@ -275,7 +275,7 @@ def normalizeToken(self, token):
275275
""" HTML5 specific normalizations to the token stream """
276276

277277
if token["type"] == tokenTypes["StartTag"]:
278-
token["data"] = OrderedDict(token['data'])
278+
token["data"] = OrderedDict(token['data'][::-1])
279279

280280
return token
281281

html5lib/tests/test_parser2.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,10 @@ def test_namespace_html_elements_1_etree():
4949

5050
def test_unicode_file():
5151
assert parse(io.StringIO("a")) is not None
52+
53+
54+
def test_duplicate_attribute():
55+
# This is here because we impl it in parser and not tokenizer
56+
doc = parse('<p class=a class=b>')
57+
el = doc[1][0]
58+
assert el.get("class") == "a"

0 commit comments

Comments
 (0)