diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2006-09-22 02:22:58 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2006-09-22 02:22:58 +0000 |
| commit | 4b5f0e2c87ba95a1e1340403d9bc737c27a0648d (patch) | |
| tree | 286945662b35630541a611048267d82d6ed0afab | |
| parent | 3cf67a9920bc00703921a3961455df44ea168dd5 (diff) | |
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
| -rw-r--r-- | django/utils/text.py | 6 |
1 files changed, 5 insertions, 1 deletions
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]+)') |
