Skip to content

Fix #239: make elementInScope consider namespaces for target #262

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

Merged
merged 1 commit into from
Jun 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions .pytest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -208,51 +208,6 @@ u'html5lib/tests/testdata/tree-construction/isindex.dat::3::cElementTree::parser
u'html5lib/tests/testdata/tree-construction/isindex.dat::3::cElementTree::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/isindex.dat::3::lxml::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/isindex.dat::3::lxml::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::0::DOM::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::0::DOM::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::0::DOM::treewalker': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::0::ElementTree::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::0::ElementTree::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::0::ElementTree::treewalker': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::0::cElementTree::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::0::cElementTree::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::0::cElementTree::treewalker': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::0::genshi::treewalker': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::0::lxml::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::0::lxml::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::0::lxml::treewalker': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::1::DOM::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::1::DOM::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::1::ElementTree::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::1::ElementTree::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::1::cElementTree::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::1::cElementTree::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::1::lxml::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::1::lxml::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::2::DOM::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::2::DOM::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::2::ElementTree::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::2::ElementTree::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::2::cElementTree::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::2::cElementTree::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::2::lxml::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::2::lxml::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::3::DOM::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::3::DOM::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::3::ElementTree::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::3::ElementTree::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::3::cElementTree::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::3::cElementTree::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::3::lxml::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::3::lxml::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::4::DOM::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::4::DOM::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::4::ElementTree::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::4::ElementTree::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::4::cElementTree::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::4::cElementTree::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::4::lxml::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/math.dat::4::lxml::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/menuitem-element.dat::3::DOM::parser::namespaced': FAIL
u'html5lib/tests/testdata/tree-construction/menuitem-element.dat::3::DOM::parser::void-namespace': FAIL
u'html5lib/tests/testdata/tree-construction/menuitem-element.dat::3::ElementTree::parser::namespaced': FAIL
Expand Down
9 changes: 7 additions & 2 deletions html5lib/treebuilders/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,17 @@ def elementInScope(self, target, variant=None):
# If we pass a node in we match that. if we pass a string
# match any node with that name
exactNode = hasattr(target, "nameTuple")
if not exactNode:
if isinstance(target, text_type):
target = (namespaces["html"], target)
assert isinstance(target, tuple)

listElements, invert = listElementsMap[variant]

for node in reversed(self.openElements):
if (node.name == target and not exactNode or
node == target and exactNode):
if exactNode and node == target:
return True
elif not exactNode and node.nameTuple == target:
return True
elif (invert ^ (node.nameTuple in listElements)):
return False
Expand Down