Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #2657 -- Made some tweaks to Javascript quoting. Thanks, Alex D…

…edul.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3782 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4b5f0e2c87ba95a1e1340403d9bc737c27a0648d 1 parent 3cf67a9
@malcolmt malcolmt authored
Showing with 5 additions and 1 deletion.
  1. +5 −1 django/utils/text.py
View
6 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 fix(match):
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]+)')

0 comments on commit 4b5f0e2

Please sign in to comment.
Something went wrong with that request. Please try again.