Ticket #2657: javascript_quote.patch
File javascript_quote.patch, 886 bytes (added by , 18 years ago) |
---|
-
django/utils/text.py
94 94 return zbuf.getvalue() 95 95 96 96 ustring_re = re.compile(u"([\u0080-\uffff])") 97 def javascript_quote(s ):97 def javascript_quote(s, quote_double_quotes=False): 98 98 99 99 def fix(match): 100 100 return r"\u%04x" % ord(match.group(1)) … … 104 104 elif type(s) != unicode: 105 105 raise TypeError, s 106 106 s = s.replace('\\', '\\\\') 107 s = s.replace('\r', '\\r') 107 108 s = s.replace('\n', '\\n') 108 109 s = s.replace('\t', '\\t') 109 110 s = s.replace("'", "\\'") 111 if quote_double_quotes: 112 s = s.replace('"', '"') 110 113 return str(ustring_re.sub(fix, s)) 111 114 112 115 smart_split_re = re.compile('("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)')