Ticket #4131: addslash_escape.diff
File addslash_escape.diff, 832 bytes (added by , 18 years ago) |
---|
-
django/template/defaultfilters.py
47 47 48 48 def addslashes(value): 49 49 "Adds slashes - useful for passing strings to JavaScript, for example." 50 return value.replace('\\', '\\\\').replace('"', '\\"').replace("'", "\\'") 50 maps = ( 51 ('\\', '\\\\'), 52 ('"', '\\"'), 53 ("'", "\\'"), 54 ('\n', '\\n'), 55 ('\r', ''), 56 ('\b', '\\b'), 57 ('\f', '\\f'), 58 ('\t', '\\t'), 59 ('\v', '\\v'), 60 ('</', '<\\/'), 61 ) 62 63 for bad, good in maps: 64 value = value.replace(bad, good) 65 return value 51 66 addslashes = stringfilter(addslashes) 52 67 53 68 def capfirst(value):