From 1c32da9882d056fee65d8c2aa44ecacfc21eb758 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Tue, 22 Feb 2011 22:45:36 -0500 Subject: Don't turn " into " except in attribute values. --- tests/test_soup.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/test_soup.py') diff --git a/tests/test_soup.py b/tests/test_soup.py index eaedd94..5df49bc 100644 --- a/tests/test_soup.py +++ b/tests/test_soup.py @@ -80,6 +80,10 @@ class TestEntitySubstitution(unittest.TestCase): self.sub.substitute_xml("ÁT&T"), "ÁT&T") + def test_quotes_not_html_substituted(self): + """There's no need to do this except inside attribute values.""" + text = 'Bob\'s "bar"' + self.assertEquals(self.sub.substitute_html(text), text) class TestUnicodeDammit(unittest.TestCase): """Standalone tests of Unicode, Dammit.""" -- cgit v1.2.3 From 6d7422139b7a60f48761f9a8ef52ed3de7393287 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Tue, 22 Feb 2011 22:56:09 -0500 Subject: Solved the question of how to decide between ' (XML) and &squot; (HTML) by cutting the Gordian knot: quote the *double* quotes, which are always ". --- tests/test_soup.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'tests/test_soup.py') diff --git a/tests/test_soup.py b/tests/test_soup.py index 5df49bc..c4d9c2c 100644 --- a/tests/test_soup.py +++ b/tests/test_soup.py @@ -53,15 +53,9 @@ class TestEntitySubstitution(unittest.TestCase): def test_xml_attribute_quoting_escapes_single_quotes_when_value_contains_both_single_and_double_quotes(self): s = 'Welcome to "Bob\'s Bar"' - # This one is going into an HTML document. self.assertEquals( self.sub.substitute_xml(s, True), - "'Welcome to \"Bob&squot;s Bar\"'") - - # This one is going into an XML document. - self.assertEquals( - self.sub.substitute_xml(s, True, destination_is_xml=True), - "'Welcome to \"Bob's Bar\"'") + '"Welcome to "Bob\'s Bar""') def test_xml_quotes_arent_escaped_when_value_is_not_being_quoted(self): quoted = 'Welcome to "Bob\'s Bar"' -- cgit v1.2.3