8000 alphabeticalattributes filter TypeError when comparing namespaced attributes with non-namespaced attributes · Issue #322 · html5lib/html5lib-python · GitHub
[go: up one dir, main page]

Skip to content

alphabeticalattributes filter TypeError when comparing namespaced attributes with non-namespaced attributes #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
willkg opened this issue Feb 22, 2017 · 2 comments · Fixed by #324

Comments

@willkg
Copy link
Contributor
willkg commented Feb 22, 2017

In SVG 1.1, you could have something like this:

<svg><pattern id="patt1" xlink:href="http://example.com/#whatever" /></svg>

In Python 3, that creates the following attributes:

dict_items([((None, 'id'), 'patt1'), (('http://www.w3.org/1999/xlink', 'href'), '#patt2')])

The problem is that this means we're comparing None with a str here:

That kicks up a TypeError.

Script:

import html5lib
from html5lib.serializer import HTMLSerializer


text = '<svg><pattern id="patt1" xlink:href="http://example.com/#foo" /></svg>'

parser = html5lib.HTMLParser()
dom = parser.parseFragment(text)
walker = html5lib.getTreeWalker('etree')
ser = HTMLSerializer(alphabetical_attributes=True)

ser.render(walker(dom))

Traceback:

Traceback (most recent call last):
  File "foo.py", line 12, in <module>
    ser.render(walker(dom))
  File "/home/willkg/mozilla/bleach/.tox/py34-html5lib99999999/lib/python3.4/site-packages/html5lib/serializer.py", line 323, in render
    return "".join(list(self.serialize(treewalker)))
  File "/home/willkg/mozilla/bleach/.tox/py34-html5lib99999999/lib/python3.4/site-packages/html5lib/serializer.py", line 209, in serialize
    for token in treewalker:
  File "/home/willkg/mozilla/bleach/.tox/py34-html5lib99999999/lib/python3.4/site-packages/html5lib/filters/optionaltags.py", line 18, in __iter__
    for previous, token, next in self.slider():
  File "/home/willkg/mozilla/bleach/.tox/py34-html5lib99999999/lib/python3.4/site-packages/html5lib/filters/optionaltags.py", line 9, in slider
    for token in self.source:
  File "/home/willkg/mozilla/bleach/.tox/py34-html5lib99999999/lib/python3.4/site-packages/html5lib/filters/alphabeticalattributes.py", line 17, in __iter__
    key=lambda x: x[0]):
TypeError: unorderable types: str() < NoneType()

This is true of html5lib 0.99999999 (8 9s) and 0.999999999 (9 9s).

@willkg
Copy link
Contributor Author
willkg commented Feb 22, 2017

I'm pretty sure this is an easy fix in alphabeticalattributes. If I throw together a PR, will someone help me land it?

@gsnedders
Copy link
Member

Sure!

gsnedders pushed a commit that referenced this issue Aug 31, 2017
If a tag has an attribute with a None namespace and one with a str namespace,
then this filter would fail with a TypeError in Python 3. This fixes that.

Fixes #322
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0