diff options
author | Leonard Richardson <leonardr@segfault.org> | 2018-07-14 22:49:10 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2018-07-14 22:49:10 -0400 |
commit | a0457769bbdc682569dd41a48ae5acb1f21481cb (patch) | |
tree | bf505f4c39aed7e294516f851348b5daaaa3c270 /bs4/element.py | |
parent | 9cffd5984531d4cc7f07132da6859d8379b4c383 (diff) |
Fixed a disconnected parse tree when one BeautifulSoup object was
inserted into another. [bug=1105148]
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/bs4/element.py b/bs4/element.py index e4f2303..5ee9887 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -319,6 +319,14 @@ class PageElement(object): and not isinstance(new_child, NavigableString)): new_child = NavigableString(new_child) + from bs4 import BeautifulSoup + if isinstance(new_child, BeautifulSoup): + # We don't want to end up with a situation where one BeautifulSoup + # object contains another. Insert the children one at a time. + for subchild in list(new_child.contents): + self.insert(position, subchild) + position += 1 + return position = min(position, len(self.contents)) if hasattr(new_child, 'parent') and new_child.parent is not None: # We're 'inserting' an element that's already one |