tests: Add unit tests for the escaping of quote characters in attribute values
This commit is contained in:
parent
89acc4c95b
commit
7739f058c3
2 changed files with 45 additions and 1 deletions
38
testscour.py
38
testscour.py
|
|
@ -1779,7 +1779,43 @@ class XmlEntities(unittest.TestCase):
|
||||||
|
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
self.assertEqual(makeWellFormed('<>&'), '<>&',
|
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):
|
class DoNotStripCommentsOutsideOfRoot(unittest.TestCase):
|
||||||
|
|
|
||||||
8
unittests/entities.svg
Normal file
8
unittests/entities.svg
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg"
|
||||||
|
a="'"
|
||||||
|
b='"'
|
||||||
|
c="''""
|
||||||
|
d='""''
|
||||||
|
e='''""'
|
||||||
|
/>
|
||||||
|
After Width: | Height: | Size: 144 B |
Loading…
Add table
Add a link
Reference in a new issue