Don't escape quotes ('/") in text nodes and attributes.

- In text nodes quotes are fine
- In attributes quotes are fine if used reciprocally.

Escaping in the latter case often causes issues, e.g. with quoted font names (#21) or inline CSS styles (#56), while it probably does not gain anything (if quotes are wrongly used in attribute names the XML is most likely invalid to start with)
This commit is contained in:
Eduard Braun 2016-08-16 00:07:29 +02:00
parent fe2884c3e8
commit 738b7d7c5d
2 changed files with 5 additions and 2 deletions

View file

@ -2752,7 +2752,10 @@ def remapNamespacePrefix(node, oldprefix, newprefix):
def makeWellFormed(str):
xml_ents = { '<':'&lt;', '>':'&gt;', '&':'&amp;', "'":'&apos;', '"':'&quot;'}
# Don't escape quotation marks for now as they are fine in text nodes
# as well as in attributes if used reciprocally
# xml_ents = { '<':'&lt;', '>':'&gt;', '&':'&amp;', "'":'&apos;', '"':'&quot;'}
xml_ents = { '<':'&lt;', '>':'&gt;', '&':'&amp;'}
# starr = []
# for c in str:

View file

@ -1114,7 +1114,7 @@ class EnsureLineEndings(unittest.TestCase):
class XmlEntities(unittest.TestCase):
def runTest(self):
self.assertEqual( scour.makeWellFormed('<>&"\''), '&lt;&gt;&amp;&quot;&apos;',
self.assertEqual( scour.makeWellFormed('<>&'), '&lt;&gt;&amp;',
'Incorrectly translated XML entities')
class DoNotStripCommentsOutsideOfRoot(unittest.TestCase):