diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2011-02-22 22:57:39 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2011-02-22 22:57:39 -0500 |
commit | 7db58f67d60bf2675613e38d2d8daeeadc5522db (patch) | |
tree | 6cacead21b43bb5de23947a414c5d949c0d6c434 /tests | |
parent | f42fef27dc82ce97df0cb7b254595e6771461637 (diff) | |
parent | 6d7422139b7a60f48761f9a8ef52ed3de7393287 (diff) |
Solved the question of how to decide between ' (XML) and &squot; (HTML) by cutting the Gordian knot: quote the *double* quotes, which are always ".
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_lxml.py | 2 | ||||
-rw-r--r-- | tests/test_soup.py | 12 |
2 files changed, 6 insertions, 8 deletions
diff --git a/tests/test_lxml.py b/tests/test_lxml.py index df2f341..8f3d798 100644 --- a/tests/test_lxml.py +++ b/tests/test_lxml.py @@ -125,7 +125,7 @@ class TestLXMLBuilder(SoupTest): soup.foo['attr'] = 'Brawls happen at "Bob\'s Bar"' self.assertSoupEquals( soup.foo.decode(), - """<foo attr='Brawls happen at "Bob&squot;s Bar"'>a</foo>""") + """<foo attr="Brawls happen at "Bob\'s Bar"">a</foo>""") def test_ampersand_in_attribute_value_gets_quoted(self): self.assertSoupEquals('<this is="really messed up & stuff"></this>', diff --git a/tests/test_soup.py b/tests/test_soup.py index eaedd94..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"' @@ -80,6 +74,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.""" |