Ticket #15034: 15034-technical-500-response-r15153.diff

File 15034-technical-500-response-r15153.diff, 2.0 KB (added by Tai Lee, 14 years ago)
  • django/views/debug.py

     
    88from django.http import HttpResponse, HttpResponseServerError, HttpResponseNotFound
    99from django.template import (Template, Context, TemplateDoesNotExist,
    1010    TemplateSyntaxError)
     11from django.template.defaultfilters import force_escape, pprint
    1112from django.utils.html import escape
    1213from django.utils.importlib import import_module
    1314from django.utils.encoding import smart_unicode, smart_str
    1415
    15 
    1616HIDDEN_SETTINGS = re.compile('SECRET|PASSWORD|PROFANITIES_LIST|SIGNATURE')
    1717
    1818def linebreak_iter(template_source):
     
    109109            self.get_template_exception_info()
    110110
    111111        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
    112115
    113116        unicode_hint = ''
    114117        if issubclass(self.exc_type, UnicodeError):
     
    547550                {% for var in frame.vars|dictsort:"0" %}
    548551                  <tr>
    549552                    <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>
    551554                  </tr>
    552555                {% endfor %}
    553556              </tbody>
  • tests/regressiontests/views/views.py

     
    3636        form_class=SlugChangingArticleForm)
    3737
    3838def 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/15034
     42    def callable():
     43        raise Exception
    3944    try:
    4045        raise Exception
    4146    except Exception:
Back to Top