diff options
author | Leonard Richardson <leonardr@segfault.org> | 2016-07-17 11:50:48 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2016-07-17 11:50:48 -0400 |
commit | 0b2445d80c360980c948821c287da56f63629257 (patch) | |
tree | 8d8b04f40f03fdd26b3bbcdc58ce191756270336 /bs4/__init__.py | |
parent | dfe49a14ef02589d96953434fb9aeab7da5ccb30 (diff) |
Fixed a bug in the html5lib treebuilder that deranged the tree
when a whitespace element was reparented into a tag that contained
an identical whitespace element. [bug=1505351]
Diffstat (limited to 'bs4/__init__.py')
-rw-r--r-- | bs4/__init__.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/bs4/__init__.py b/bs4/__init__.py index 37993ce..003dccb 100644 --- a/bs4/__init__.py +++ b/bs4/__init__.py @@ -376,7 +376,18 @@ class BeautifulSoup(Tag): if parent.next_sibling: # This node is being inserted into an element that has # already been parsed. Deal with any dangling references. - index = parent.contents.index(o) + index = len(parent.contents)-1 + while index >= 0: + if parent.contents[index] is o: + break + index -= 1 + else: + raise ValueError( + "Error in html5lib tree builder: supposedly %r was " + "inserted into %r, but I don't see it!" % ( + o, parent + ) + ) if index == 0: previous_element = parent previous_sibling = None |