Ticket #2657: javascript_quote.patch

File javascript_quote.patch, 886 bytes (added by Alex Dedul, 18 years ago)
  • django/utils/text.py

     
    9494    return zbuf.getvalue()
    9595
    9696ustring_re = re.compile(u"([\u0080-\uffff])")
    97 def javascript_quote(s):
     97def javascript_quote(s, quote_double_quotes=False):
    9898
    9999    def fix(match):
    100100        return r"\u%04x" % ord(match.group(1))
     
    104104    elif type(s) != unicode:
    105105        raise TypeError, s
    106106    s = s.replace('\\', '\\\\')
     107    s = s.replace('\r', '\\r')
    107108    s = s.replace('\n', '\\n')
    108109    s = s.replace('\t', '\\t')
    109110    s = s.replace("'", "\\'")
     111    if quote_double_quotes:
     112        s = s.replace('"', '"')
    110113    return str(ustring_re.sub(fix, s))
    111114
    112115smart_split_re = re.compile('("(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'|[^\\s]+)')
Back to Top