summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS.txt6
-rw-r--r--bs4/element.py2
-rw-r--r--bs4/tests/test_tree.py25
-rw-r--r--doc/source/index.rst2
4 files changed, 33 insertions, 2 deletions
diff --git a/NEWS.txt b/NEWS.txt
index 2548e4e..9b90da2 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -1,8 +1,12 @@
-= Unreleased
+= 4.4.1 (20150928) =
* Fixed the test_detect_utf8 test so that it works when chardet is
installed. [bug=1471359]
+* Fixed a bug that deranged the tree when part of it was
+ removed. Thanks to Eric Weiser for the patch and John Wiseman for a
+ test. [bug=1481520]
+
= 4.4.0 (20150703) =
Especially important changes:
diff --git a/bs4/element.py b/bs4/element.py
index 60464b6..02fd1b7 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -294,6 +294,8 @@ class PageElement(object):
_lastRecursiveChild = _last_descendant
def insert(self, position, new_child):
+ if new_child is None:
+ raise ValueError("Cannot insert None into a tag.")
if new_child is self:
raise ValueError("Cannot insert a tag into itself.")
if (isinstance(new_child, basestring)
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py
index 2371591..ab21a50 100644
--- a/bs4/tests/test_tree.py
+++ b/bs4/tests/test_tree.py
@@ -1084,6 +1084,31 @@ class TestTreeModification(SoupTest):
self.assertEqual(foo_2, soup.a.string)
self.assertEqual(bar_2, soup.b.string)
+ def test_extract_multiples_of_same_tag(self):
+ soup = self.soup("""
+<html>
+<head>
+<script>foo</script>
+</head>
+<body>
+ <script>bar</script>
+ <a></a>
+</body>
+<script>baz</script>
+</html>""")
+ [soup.script.extract() for i in soup.find_all("script")]
+ self.assertEqual("<body>\n\n<a></a>\n</body>", unicode(soup.body))
+
+
+ def test_extract_works_when_element_is_surrounded_by_identical_strings(self):
+ soup = self.soup(
+ '<html>\n'
+ '<body>hi</body>\n'
+ '</html>')
+ soup.find('body').extract()
+ self.assertEqual(None, soup.find('body'))
+
+
def test_clear(self):
"""Tag.clear()"""
soup = self.soup("<p><a>String <em>Italicized</em></a> and another</p>")
diff --git a/doc/source/index.rst b/doc/source/index.rst
index ba3b54e..3bc9537 100644
--- a/doc/source/index.rst
+++ b/doc/source/index.rst
@@ -29,7 +29,7 @@ Soup 3 and Beautiful Soup 4, see `Porting code to BS4`_.
This documentation has been translated into other languages by
Beautiful Soup users:
-* `这篇文档当然还有中文版. <http://www.crummy.com/software/BeautifulSoup/bs4/doc/index.cn.html>`_
+* `这篇文档当然还有中文版. <http://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/>`_
* このページは日本語で利用できます(`外部リンク <http://kondou.com/BS4/>`_)
* 이 문서는 한국어 번역도 가능합니다. (`외부 링크 <http://coreapython.hosting.paran.com/etc/beautifulsoup4.html>`_)