diff options
Diffstat (limited to 'bs4')
-rw-r--r-- | bs4/__init__.py | 4 | ||||
-rw-r--r-- | bs4/element.py | 5 | ||||
-rw-r--r-- | bs4/tests/test_tree.py | 9 |
3 files changed, 17 insertions, 1 deletions
diff --git a/bs4/__init__.py b/bs4/__init__.py index 73109d6..2b82864 100644 --- a/bs4/__init__.py +++ b/bs4/__init__.py @@ -253,7 +253,9 @@ class BeautifulSoup(Tag): if not original_builder and not ( original_features == builder.NAME or original_features in builder.ALTERNATE_NAMES - ): + ) and markup: + # The user did not tell us which TreeBuilder to use, + # and we had to guess. Issue a warning. if builder.is_xml: markup_type = "XML" else: diff --git a/bs4/element.py b/bs4/element.py index 130dfa9..370b153 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -457,6 +457,11 @@ class PageElement(object): :param tags: A list of PageElements. """ + if isinstance(tags, Tag): + # Calling self.append() on another tag's contents will change + # the list we're iterating over. Make a list that won't + # change. + tags = list(tags.contents) for tag in tags: self.append(tag) diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index 7981130..2246346 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -1009,6 +1009,15 @@ class TestTreeModification(SoupTest): soup.a.extend(l) self.assertEqual("<a><g></g><f></f><e></e><d></d><c></c><b></b></a>", soup.decode()) + def test_extend_with_another_tags_contents(self): + data = '<body><div id="d1"><a>1</a><a>2</a><a>3</a><a>4</a></div><div id="d2"></div></body>' + soup = self.soup(data) + d1 = soup.find('div', id='d1') + d2 = soup.find('div', id='d2') + d2.extend(d1) + self.assertEqual(u'<div id="d1"></div>', d1.decode()) + self.assertEqual(u'<div id="d2"><a>1</a><a>2</a><a>3</a><a>4</a></div>', d2.decode()) + def test_move_tag_to_beginning_of_parent(self): data = "<a><b></b><c></c><d></d></a>" soup = self.soup(data) |