diff --git a/testscour.py b/testscour.py index 8ebaf9d..8054371 100755 --- a/testscour.py +++ b/testscour.py @@ -1779,7 +1779,43 @@ class XmlEntities(unittest.TestCase): def runTest(self): self.assertEqual(makeWellFormed('<>&'), '<>&', - 'Incorrectly translated XML entities') + 'Incorrectly translated unquoted XML entities') + self.assertEqual(makeWellFormed('<>&', "'"), '<>&', + 'Incorrectly translated single-quoted XML entities') + self.assertEqual(makeWellFormed('<>&', '"'), '<>&', + 'Incorrectly translated double-quoted XML entities') + + self.assertEqual(makeWellFormed("'"), "'", + 'Incorrectly translated unquoted single quote') + self.assertEqual(makeWellFormed('"'), '"', + 'Incorrectly translated unquoted double quote') + + self.assertEqual(makeWellFormed("'", '"'), "'", + 'Incorrectly translated double-quoted single quote') + self.assertEqual(makeWellFormed('"', "'"), '"', + 'Incorrectly translated single-quoted double quote') + + self.assertEqual(makeWellFormed("'", "'"), ''', + 'Incorrectly translated single-quoted single quote') + self.assertEqual(makeWellFormed('"', '"'), '"', + 'Incorrectly translated double-quoted double quote') + + +class HandleQuotesInAttributes(unittest.TestCase): + + def runTest(self): + with open('unittests/entities.svg', "rb") as f: + output = scourString(f.read()) + self.assertTrue('a="\'"' in output, + 'Failed on attribute value with non-double quote') + self.assertTrue("b='\"'" in output, + 'Failed on attribute value with non-single quote') + self.assertTrue("c=\"''"\"" in output, + 'Failed on attribute value with more single quotes than double quotes') + self.assertTrue('d=\'""'\'' in output, + 'Failed on attribute value with more double quotes than single quotes') + self.assertTrue("e=\"''""\"" in output, + 'Failed on attribute value with the same number of double quotes as single quotes') class DoNotStripCommentsOutsideOfRoot(unittest.TestCase): diff --git a/unittests/entities.svg b/unittests/entities.svg new file mode 100644 index 0000000..2308b46 --- /dev/null +++ b/unittests/entities.svg @@ -0,0 +1,8 @@ + +