Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15025 - template debug fails if there's a callable local var t…

…hat generates an exception

Thanks to Tai Lee for the patch and report, also to Don Spaulding.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15187 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 80f48260630c3db98f6e0af282bc339eba999009 1 parent e1ede21
Luke Plant authored January 13, 2011
7  django/views/debug.py
@@ -8,11 +8,11 @@
8 8
 from django.http import HttpResponse, HttpResponseServerError, HttpResponseNotFound
9 9
 from django.template import (Template, Context, TemplateDoesNotExist,
10 10
     TemplateSyntaxError)
  11
+from django.template.defaultfilters import force_escape, pprint
11 12
 from django.utils.html import escape
12 13
 from django.utils.importlib import import_module
13 14
 from django.utils.encoding import smart_unicode, smart_str
14 15
 
15  
-
16 16
 HIDDEN_SETTINGS = re.compile('SECRET|PASSWORD|PROFANITIES_LIST|SIGNATURE')
17 17
 
18 18
 def linebreak_iter(template_source):
@@ -109,6 +109,9 @@ def get_traceback_html(self):
109 109
             self.get_template_exception_info()
110 110
 
111 111
         frames = self.get_traceback_frames()
  112
+        for i, frame in enumerate(frames):
  113
+            frame['vars'] = [(k, force_escape(pprint(v))) for k, v in frame['vars']]
  114
+            frames[i] = frame
112 115
 
113 116
         unicode_hint = ''
114 117
         if issubclass(self.exc_type, UnicodeError):
@@ -547,7 +550,7 @@ def empty_urlconf(request):
547 550
                 {% for var in frame.vars|dictsort:"0" %}
548 551
                   <tr>
549 552
                     <td>{{ var.0|force_escape }}</td>
550  
-                    <td class="code"><pre>{{ var.1|pprint|force_escape }}</pre></td>
  553
+                    <td class="code"><pre>{{ var.1 }}</pre></td>
551 554
                   </tr>
552 555
                 {% endfor %}
553 556
               </tbody>
5  tests/regressiontests/views/views.py
@@ -36,6 +36,11 @@ def save(self, *args, **kwargs):
36 36
         form_class=SlugChangingArticleForm)
37 37
 
38 38
 def raises(request):
  39
+    # Make sure that a callable that raises an exception in the stack frame's
  40
+    # local vars won't hijack the technical 500 response. See:
  41
+    # http://code.djangoproject.com/ticket/15025
  42
+    def callable():
  43
+        raise Exception
39 44
     try:
40 45
         raise Exception
41 46
     except Exception:

0 notes on commit 80f4826

Please sign in to comment.
Something went wrong with that request. Please try again.