Skip to content

Commit

Permalink
[1.6.x] Fix #21185: Added tests for unescape_entities.
Browse files Browse the repository at this point in the history
Also fixed a py3 incompatibility.
Thanks to brutasse for the report.

Backport of 3754f4a from master.
  • Loading branch information
bmispelon committed Sep 27, 2013
1 parent f621aba commit 15bdc85
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions django/utils/text.py
Expand Up @@ -365,12 +365,12 @@ def _replace_entity(match):
c = int(text[1:], 16)
else:
c = int(text)
return unichr(c)
return six.unichr(c)
except ValueError:
return match.group(0)
else:
try:
return unichr(html_entities.name2codepoint[text])
return six.unichr(html_entities.name2codepoint[text])
except (ValueError, KeyError):
return match.group(0)

Expand Down
13 changes: 13 additions & 0 deletions tests/utils_tests/test_text.py
Expand Up @@ -106,3 +106,16 @@ def test_slugify(self):
)
for value, output in items:
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)

0 comments on commit 15bdc85

Please sign in to comment.