Ticket #11778: patch.diff

File patch.diff, 885 bytes (added by josephdrose, 6 years ago)
  • django/template/defaultfilters.py

     
    8585_js_escapes = (_base_js_escapes +
    8686               tuple([('%c' % z, '\\x%02X' % z) for z in range(32)]))
    8787
     88_js_escapes_dict={}
     89for k, v in _js_escapes:
     90    _js_escapes_dict[k]=v
     91
     92_js_escapes_re = re.compile(u'[\u0000-\u001f]|\\\\|\'|"|>|<|&|=|-|;')
     93
    8894def escapejs(value):
    89     """Hex encodes characters for use in JavaScript strings."""
    90     for bad, good in _js_escapes:
    91         value = value.replace(bad, good)
    92     return value
     95    """Hex encodes characters for use in JavaScript strings."""
     96    return _js_escapes_re.sub(lambda m: _js_escapes_dict[m.group(0)], value)
    9397escapejs = stringfilter(escapejs)
    9498
    9599def fix_ampersands(value):
Back to Top