Skip to content

Commit 270a2ca

Browse files
committed
Don't let the lxml treewalker walk above the fragment root
1 parent 8b4d7c4 commit 270a2ca

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

html5lib/treewalkers/lxmletree.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ def __len__(self):
118118
class TreeWalker(_base.NonRecursiveTreeWalker):
119119
def __init__(self, tree):
120120
if hasattr(tree, "getroot"):
121+
self.fragmentChildren = set()
121122
tree = Root(tree)
122123
elif isinstance(tree, list):
124+
self.fragmentChildren = set(tree)
123125
tree = FragmentRoot(tree)
124126
_base.NonRecursiveTreeWalker.__init__(self, tree)
125127
self.filter = ihatexml.InfosetFilter()
@@ -197,5 +199,7 @@ def getParentNode(self, node):
197199
if key == "text":
198200
return node
199201
# else: fallback to "normal" processing
202+
elif node in self.fragmentChildren:
203+
return None
200204

201205
return node.getparent()

0 commit comments

Comments
 (0)