Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

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

Backport of 3754f4a from master.
  • Loading branch information...
commit 73ffe26816738c15515e5764e96c056f0d98559a 1 parent cb95516
@bmispelon bmispelon authored
Showing with 15 additions and 2 deletions.
  1. +2 −2 django/utils/text.py
  2. +13 −0 tests/regressiontests/utils/text.py
View
4 django/utils/text.py
@@ -381,12 +381,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)
View
13 tests/regressiontests/utils/text.py
@@ -121,3 +121,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)
Please sign in to comment.
Something went wrong with that request. Please try again.