test: escape_xml

pull/442/head
QuentinN42 3 years ago
parent dab7a8089b
commit b1ce2f290b
No known key found for this signature in database
GPG Key ID: 2CD7D563712B3A50

File diff suppressed because it is too large Load Diff

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
import unittest
import string
from yamllint.format import escape_xml, severity_from_level
class TextToXMLTestCase(unittest.TestCase):
specials = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&apos;'
}
def test_letters_chars(self):
txt = string.ascii_letters
self.assertEqual(escape_xml(txt), txt)
def test_specials_chars(self):
for inp, out in self.specials.items():
self.assertEqual(escape_xml(inp), out)

@ -37,7 +37,7 @@ def escape_xml(text):
text = text.replace('<', '&lt;')
text = text.replace('>', '&gt;')
text = text.replace('"', '&quot;')
text = text.replace('"', '&apos;')
text = text.replace("'", '&apos;')
return text

Loading…
Cancel
Save