[1.6.x] Fix #21185: Added tests for unescape_entities.

Also fixed a py3 incompatibility.
Thanks to brutasse for the report.

Backport of 3754f4ad41 from master.
This commit is contained in:
Baptiste Mispelon 2013-09-27 17:00:42 +02:00
parent f621aba99b
commit 15bdc85117
2 changed files with 15 additions and 2 deletions

View File

@ -365,12 +365,12 @@ def _replace_entity(match):
c = int(text[1:], 16) c = int(text[1:], 16)
else: else:
c = int(text) c = int(text)
return unichr(c) return six.unichr(c)
except ValueError: except ValueError:
return match.group(0) return match.group(0)
else: else:
try: try:
return unichr(html_entities.name2codepoint[text]) return six.unichr(html_entities.name2codepoint[text])
except (ValueError, KeyError): except (ValueError, KeyError):
return match.group(0) return match.group(0)

View File

@ -106,3 +106,16 @@ class TestUtilsText(SimpleTestCase):
) )
for value, output in items: for value, output in items:
self.assertEqual(text.slugify(value), output) self.assertEqual(text.slugify(value), output)
def test_unescape_entities(self):
items = [
('', ''),
('foo', 'foo'),
('&', '&'),
('&', '&'),
('&', '&'),
('foo & bar', 'foo & bar'),
('foo & bar', 'foo & bar'),
]
for value, output in items:
self.assertEqual(text.unescape_entities(value), output)