Ticket #2986: addslashes.patch
File addslashes.patch, 2.1 KB (added by , 18 years ago) |
---|
-
django/contrib/admin/views/main.py
12 12 from django.http import Http404, HttpResponse, HttpResponseRedirect 13 13 from django.utils.html import escape 14 14 from django.utils.text import capfirst, get_text_list 15 from django.template.defaultfilters import addslashes 15 16 import operator 16 17 17 18 from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, DELETION … … 263 264 post_url_continue += "?_popup=1" 264 265 return HttpResponseRedirect(post_url_continue % pk_value) 265 266 if request.POST.has_key("_popup"): 267 print pk_value 266 268 if type(pk_value) is str: # Quote if string, so JavaScript doesn't think it's a variable. 267 pk_value = '"%s"' % pk_value.replace('"', '\\"')269 pk_value = '"%s"' % addslashes(pk_value) 268 270 return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, %s, "%s");</script>' % \ 269 (pk_value, str(new_object).replace('"', '\\"')))271 (pk_value, addslashes(str(new_object)))) 270 272 elif request.POST.has_key("_addanother"): 271 273 request.user.message_set.create(message=msg + ' ' + (_("You may add another %s below.") % opts.verbose_name)) 272 274 return HttpResponseRedirect(request.path) -
django/template/defaultfilters.py
15 15 16 16 def addslashes(value): 17 17 "Adds slashes - useful for passing strings to JavaScript, for example." 18 return value.replace('\\', '\\\\').replace('"', '\\"').replace("'", "\\'") 18 return value.replace('\\', '\\\\').replace('"', '\\"').replace("'", "\\'").replace('\n', '\\n') 19 19 20 20 def capfirst(value): 21 21 "Capitalizes the first character of the value"