Fix case-insensitive HTML insertion

Keeps the case-insensitive search for "</body>" and removes extra scan for the
tag by trying to insert the toolbar, and warning if unsuccessful.
This commit is contained in:
Matt Good
2015-04-16 14:47:46 -07:00
parent f6e37be73c
commit 2d60ea6c8d

View File

@@ -170,16 +170,16 @@ class DebugToolbarExtension(object):
if response.is_sequence:
response_html = response.data.decode(response.charset)
if "</body>" in response_html:
toolbar_html = self.debug_toolbars[real_request].render_toolbar()
toolbar_html = self.debug_toolbars[real_request].render_toolbar()
content = replace_insensitive(
response_html, '</body>', toolbar_html + '</body>')
content = replace_insensitive(
response_html, '</body>', toolbar_html + '</body>')
if content is response_html:
warnings.warn('Could not insert debug toolbar. </body> tag not found in response.')
else:
content = content.encode(response.charset)
response.response = [content]
response.content_length = len(content)
else:
warnings.warn("Could not insert debug toolbar. <body> element not found in response.")
return response