summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaptiste Mispelon <bmispelon@gmail.com>2013-09-27 17:00:42 +0200
committerBaptiste Mispelon <bmispelon@gmail.com>2013-09-27 18:45:26 +0200
commit73ffe26816738c15515e5764e96c056f0d98559a (patch)
tree19d566ff1a3d44ebac66c54c7f660e51fc6420c0
parentcb95516a880d62059825fc1fd154f457abb8075d (diff)
[1.5.x] Fix #21185: Added tests for unescape_entities.
Also fixed a py3 incompatibility. Thanks to brutasse for the report. Backport of 3754f4ad410640382f9fe25073da03009cdc2ea3 from master.
-rw-r--r--django/utils/text.py4
-rw-r--r--tests/regressiontests/utils/text.py13
2 files changed, 15 insertions, 2 deletions
diff --git a/django/utils/text.py b/django/utils/text.py
index d75ca8dbca..03cfd556f2 100644
--- a/django/utils/text.py
+++ b/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)
diff --git a/tests/regressiontests/utils/text.py b/tests/regressiontests/utils/text.py
index ebf67952f9..3709dcd11c 100644
--- a/tests/regressiontests/utils/text.py
+++ b/tests/regressiontests/utils/text.py
@@ -121,3 +121,16 @@ class TestUtilsText(SimpleTestCase):
)
for value, output in items:
self.assertEqual(text.slugify(value), output)
+
+ def test_unescape_entities(self):
+ items = [
+ ('', ''),
+ ('foo', 'foo'),
+ ('&amp;', '&'),
+ ('&#x26;', '&'),
+ ('&#38;', '&'),
+ ('foo &amp; bar', 'foo & bar'),
+ ('foo & bar', 'foo & bar'),
+ ]
+ for value, output in items:
+ self.assertEqual(text.unescape_entities(value), output)