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
This commit is contained in:
Malcolm Tredinnick 2006-09-22 02:22:58 +00:00
parent 3cf67a9920
commit 4b5f0e2c87
1 changed files with 5 additions and 1 deletions

View File

@ -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]+)')