Ticket #7177: django_js_escapes.diff
File django_js_escapes.diff, 1.7 KB (added by , 17 years ago) |
---|
-
django/template/defaultfilters.py
63 63 capfirst = stringfilter(capfirst) 64 64 65 65 _js_escapes = ( 66 ('\\', '\\\\'), 67 ('"', '\\"'), 68 ("'", "\\'"), 69 ('\n', '\\n'), 70 ('\r', '\\r'), 71 ('\b', '\\b'), 72 ('\f', '\\f'), 73 ('\t', '\\t'), 74 ('\v', '\\v'), 75 ('</', '<\\/'), 66 ('\'', r'\x27'), 67 ('"', r'\x22'), 68 ('\\', r'\x5C'), 69 ('>', r'\x3E'), 70 ('<', r'\x3C'), 71 ('&', r'\x26'), 72 ('=', r'\x3D'), 73 ('-', r'\x2D'), 74 (';', r'\x3B'), 75 ('\x00', r'\x00'), 76 ('\x01', r'\x01'), 77 ('\x02', r'\x02'), 78 ('\x03', r'\x03'), 79 ('\x04', r'\x04'), 80 ('\x05', r'\x05'), 81 ('\x06', r'\x06'), 82 ('\x07', r'\x07'), 83 ('\x08', r'\x08'), 84 ('\x09', r'\x09'), 85 ('\x0A', r'\x0A'), 86 ('\x0B', r'\x0B'), 87 ('\x0C', r'\x0C'), 88 ('\x0D', r'\x0D'), 89 ('\x0E', r'\x0E'), 90 ('\x0F', r'\x0F'), 91 ('\x10', r'\x10'), 92 ('\x11', r'\x11'), 93 ('\x12', r'\x12'), 94 ('\x13', r'\x13'), 95 ('\x14', r'\x14'), 96 ('\x15', r'\x15'), 97 ('\x16', r'\x16'), 98 ('\x17', r'\x17'), 99 ('\x18', r'\x18'), 100 ('\x19', r'\x19'), 101 ('\x1A', r'\x1A'), 102 ('\x1B', r'\x1B'), 103 ('\x1C', r'\x1C'), 104 ('\x1D', r'\x1D'), 105 ('\x1E', r'\x1E'), 106 ('\x1F', r'\x1F'), 76 107 ) 77 108 def escapejs(value): 78 """ Backslash-escapes characters for use in JavaScript strings."""109 """Hex encodes characters for use in JavaScript strings.""" 79 110 for bad, good in _js_escapes: 80 111 value = value.replace(bad, good) 81 112 return value