diff options
author | Leonard Richardson <leonardr@segfault.org> | 2019-01-06 18:49:34 -0500 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2019-01-06 18:49:34 -0500 |
commit | 9c99d3050584a088b1d066aca0c21d04f87775b0 (patch) | |
tree | 1ccfcba0217d9d1c8546a55f61a467b5564ab9e3 | |
parent | 4ea083fedb7bc813e7f4677b437488588d399c37 (diff) | |
download | beautifulsoup4-9c99d3050584a088b1d066aca0c21d04f87775b0.tar.gz |
Fixed an incorrectly raised exception when inserting a tag before or
after an identical tag. [bug=1810692]
-rw-r--r-- | CHANGELOG | 10 | ||||
-rw-r--r-- | bs4/element.py | 4 | ||||
-rw-r--r-- | bs4/tests/test_tree.py | 8 |
3 files changed, 20 insertions, 2 deletions
@@ -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>") |