Ticket #11778: escapejs.patch

File escapejs.patch, 828 bytes (added by gisle, 15 years ago)

Patch update to make it pass the 'defaultfilters' test (added match on \u2028\u2029)

  • django/template/defaultfilters.py

    diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
    index e6492dc..6447a4e 100644
    a b _base_js_escapes = (  
    8686_js_escapes = (_base_js_escapes +
    8787               tuple([('%c' % z, '\\x%02X' % z) for z in range(32)]))
    8888
     89_js_escapes_dict={}
     90for k, v in _js_escapes:
     91    _js_escapes_dict[k]=v
     92
     93_js_escapes_re = re.compile(u'[\u0000-\u001f\u2028\u2029]|\\\\|\'|"|>|<|&|=|-|;')
     94
    8995def escapejs(value):
    9096    """Hex encodes characters for use in JavaScript strings."""
    91     for bad, good in _js_escapes:
    92         value = value.replace(bad, good)
    93     return value
     97    return _js_escapes_re.sub(lambda m: _js_escapes_dict[m.group(0)], value)
    9498escapejs = stringfilter(escapejs)
    9599
    96100def fix_ampersands(value):
Back to Top