From 8931d8d68872f3b0742dafe02f4ab39d610c82e3 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sun, 12 Apr 2009 04:55:41 +0000 Subject: [PATCH] Fixed #10675 -- Added unicode paragraph and line-sep handling to escapejs. There were a couple of line breaking Unicode characters (\u2028 and \u2029) that cause Javascript errors, at least in Firefox, if not escaped. So now we do so. Based on a patch from rleland. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10543 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/template/defaultfilters.py | 4 +++- tests/regressiontests/defaultfilters/tests.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 7db6715b4960c..47e116cd1a469 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -76,7 +76,9 @@ def capfirst(value): ('&', r'\x26'), ('=', r'\x3D'), ('-', r'\x2D'), - (';', r'\x3B') + (';', r'\x3B'), + (u'\u2028', r'\u2028'), + (u'\u2029', r'\u2029') ) # Escape every ASCII character with a value less than 32. diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py index 027fcbba7d4aa..4343586c48bb5 100644 --- a/tests/regressiontests/defaultfilters/tests.py +++ b/tests/regressiontests/defaultfilters/tests.py @@ -83,6 +83,9 @@ >>> escapejs(ur'') u'\\x3Cscript\\x3Eand this\\x3C/script\\x3E' +>>> escapejs(u'paragraph separator:\u2029and line separator:\u2028') +u'paragraph separator:\\u2029and line separator:\\u2028' + >>> fix_ampersands(u'Jack & Jill & Jeroboam') u'Jack & Jill & Jeroboam'