From 9f437ea591aeaf16d593350baf081315e56a8b73 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sun, 20 Feb 2011 09:54:22 -0500 Subject: Added a test showing weird behavior when you .insert contents into an empty-element tag. --- CHANGELOG | 6 +++--- tests/test_tree.py | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ef05813..96a9ed4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -59,9 +59,9 @@ The value of a.string used to be None, and now it's "foo". Beautiful Soup's handling of empty-element tags (aka self-closing tags) has been improved, especially when parsing XML. Previously you -had to explicitly specify a list of empty-element tags. You can still -do that, but if you don't, Beautiful Soup now considers any empty tag -to be an empty-element tag. +had to explicitly specify a list of empty-element tags when parsing +XML. You can still do that, but if you don't, Beautiful Soup now +considers any empty tag to be an empty-element tag. The determination of empty-element-ness is now made at runtime rather than parse time. If you add a child to an empty-element tag, it stops diff --git a/tests/test_tree.py b/tests/test_tree.py index 191f614..40643dc 100644 --- a/tests/test_tree.py +++ b/tests/test_tree.py @@ -620,6 +620,15 @@ class TestTreeModification(SoupTest): self.assertEqual(the.next, c_tag) self.assertEqual(c_tag.previous, the) + def test_insert_works_on_empty_element_tag(self): + # This is a little strange, since most HTML parsers don't allow + # markup like this to come through. But in general, we don't + # know what the parser would or wouldn't have allowed, so + # I'm letting this succeed for now. + soup = self.soup("
") + soup.br.insert(1, "Contents") + self.assertEquals(str(soup.br), "
Contents
") + def test_replace_with(self): soup = self.soup( "

There's no business like show business

") -- cgit v1.2.3