summaryrefslogtreecommitdiff
path: root/bs4/element.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2015-06-28 09:23:50 -0400
committerLeonard Richardson <leonardr@segfault.org>2015-06-28 09:23:50 -0400
commit951eee1144397fd7257fb0e812a62baa8beed24b (patch)
treee23e930f7eadc205db243e4b9c62bd8cd7139eb8 /bs4/element.py
parente7eff8b01e3890f11dacf558bd9fd71c6dcbc29e (diff)
Fixed a bug where Element.extract() could create an infinite loop in
the remaining tree.
Diffstat (limited to 'bs4/element.py')
-rw-r--r--bs4/element.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/bs4/element.py b/bs4/element.py
index 7c787b1..d1b7c12 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -261,17 +261,20 @@ class PageElement(object):
last_child = self._last_descendant()
next_element = last_child.next_element
- if self.previous_element is not None:
+ if (self.previous_element is not None and
+ self.previous_element != next_element):
self.previous_element.next_element = next_element
- if next_element is not None:
+ if next_element is not None and next_element != self.previous_element:
next_element.previous_element = self.previous_element
self.previous_element = None
last_child.next_element = None
self.parent = None
- if self.previous_sibling is not None:
+ if (self.previous_sibling is not None
+ and self.previous_sibling != self.next_sibling):
self.previous_sibling.next_sibling = self.next_sibling
- if self.next_sibling is not None:
+ if (self.next_sibling is not None
+ and self.next_sibling != self.previous_sibling):
self.next_sibling.previous_sibling = self.previous_sibling
self.previous_sibling = self.next_sibling = None
return self