Ticket #11362: csrf_double_quotes.diff
File csrf_double_quotes.diff, 1.3 KB (added by , 15 years ago) |
---|
-
middleware.py
91 91 response['Content-Type'].split(';')[0] in _HTML_TYPES: 92 92 93 93 # ensure we don't add the 'id' attribute twice (HTML validity) 94 idattributes = itertools.chain(( "id='csrfmiddlewaretoken'",),94 idattributes = itertools.chain(('id="csrfmiddlewaretoken"',), 95 95 itertools.repeat('')) 96 96 def add_csrf_field(match): 97 97 """Returns the matched <form> tag plus the added <input> element""" 98 return mark_safe(match.group() + "<div style='display:none;'>"+ \99 "<input type='hidden' "+ idattributes.next() + \100 " name='csrfmiddlewaretoken' value='"+ csrf_token + \101 "' /></div>")98 return mark_safe(match.group() + '<div style="display:none;">' + \ 99 '<input type="hidden" ' + idattributes.next() + \ 100 ' name="csrfmiddlewaretoken" value="' + csrf_token + \ 101 '" /></div>') 102 102 103 103 # Modify any POST forms 104 104 response.content = _POST_FORM_RE.sub(add_csrf_field, response.content)