From 4b5f0e2c87ba95a1e1340403d9bc737c27a0648d Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Fri, 22 Sep 2006 02:22:58 +0000 Subject: [PATCH] Fixed #2657 -- Made some tweaks to Javascript quoting. Thanks, Alex Dedul. git-svn-id: http://code.djangoproject.com/svn/django/trunk@3782 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/text.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/django/utils/text.py b/django/utils/text.py index 7df9bc03b7..9e7bb3b6c4 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -94,7 +94,8 @@ def compress_string(s): return zbuf.getvalue() ustring_re = re.compile(u"([\u0080-\uffff])") -def javascript_quote(s): + +def javascript_quote(s, quote_double_quotes=False): def fix(match): return r"\u%04x" % ord(match.group(1)) @@ -104,9 +105,12 @@ def javascript_quote(s): elif type(s) != unicode: raise TypeError, s s = s.replace('\\', '\\\\') + s = s.replace('\r', '\\r') s = s.replace('\n', '\\n') s = s.replace('\t', '\\t') s = s.replace("'", "\\'") + if quote_double_quotes: + s = s.replace('"', '"') return str(ustring_re.sub(fix, s)) smart_split_re = re.compile('("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)')