summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2019-01-06 18:49:34 -0500
committerLeonard Richardson <leonardr@segfault.org>2019-01-06 18:49:34 -0500
commit9c99d3050584a088b1d066aca0c21d04f87775b0 (patch)
tree1ccfcba0217d9d1c8546a55f61a467b5564ab9e3
parent4ea083fedb7bc813e7f4677b437488588d399c37 (diff)
downloadbeautifulsoup4-9c99d3050584a088b1d066aca0c21d04f87775b0.tar.gz
Fixed an incorrectly raised exception when inserting a tag before or
after an identical tag. [bug=1810692]
-rw-r--r--CHANGELOG10
-rw-r--r--bs4/element.py4
-rw-r--r--bs4/tests/test_tree.py8
3 files changed, 20 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG
index b778f6d..389b949 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,13 @@
+= 4.7.1 (Unreleased)
+
+* Fixed a significant performance problem introduced in 4.7.0. [bug=1810617]
+
+* Fixed an incorrectly raised exception when inserting a tag before or
+ after an identical tag. [bug=1810692]
+
+* Beautiful Soup will no longer try to keep track of namespaces that
+ are not defined with a prefix; this can confuse soupselect. [bug=1810680]
+
= 4.7.0 (20181231)
* Beautiful Soup's CSS Selector implementation has been replaced by a
diff --git a/bs4/element.py b/bs4/element.py
index c367dee..5718d31 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -455,7 +455,7 @@ class PageElement(object):
if parent is None:
raise ValueError(
"Element has no parent, so 'before' has no meaning.")
- if self in args:
+ if any(x is self for x in args):
raise ValueError("Can't insert an element before itself.")
for predecessor in args:
# Extract first so that the index won't be screwed up if they
@@ -476,7 +476,7 @@ class PageElement(object):
if parent is None:
raise ValueError(
"Element has no parent, so 'after' has no meaning.")
- if self in args:
+ if any(x is self for x in args):
raise ValueError("Can't insert an element after itself.")
offset = 0
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py
index 2290558..6d79454 100644
--- a/bs4/tests/test_tree.py
+++ b/bs4/tests/test_tree.py
@@ -971,6 +971,10 @@ class TestTreeModification(SoupTest):
# Can't insert before if an element has no parent.
b.extract()
self.assertRaises(ValueError, b.insert_before, "nope")
+
+ # Can insert an identical element
+ soup = self.soup("<a>")
+ soup.a.insert_before(soup.new_tag("a"))
def test_insert_multiple_before(self):
soup = self.soup("<a>foo</a><b>bar</b>")
@@ -1000,6 +1004,10 @@ class TestTreeModification(SoupTest):
# Can't insert after if an element has no parent.
b.extract()
self.assertRaises(ValueError, b.insert_after, "nope")
+
+ # Can insert an identical element
+ soup = self.soup("<a>")
+ soup.a.insert_before(soup.new_tag("a"))
def test_insert_multiple_after(self):
soup = self.soup("<a>foo</a><b>bar</b>")