Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Unlocalize line numbers and ids in debug 500 view.

While using USE_L10N, line numbers and IDs were printed as comma (or
locale equivalent) separated values.

Thanks Kronuz for the report and intial patch.

Fixes #20861.
  • Loading branch information...
commit 6c12cd15e990b0ff5a5e85328f0a092f4bfe8080 1 parent 3f6cc33
Ramiro Morales authored October 20, 2012
6  django/views/debug.py
@@ -227,7 +227,7 @@ def format_path_status(self, path):
227 227
         return "File exists"
228 228
 
229 229
     def get_traceback_data(self):
230  
-        "Return a Context instance containing traceback information."
  230
+        """Return a dictionary containing traceback information."""
231 231
 
232 232
         if self.exc_type and issubclass(self.exc_type, TemplateDoesNotExist):
233 233
             from django.template.loader import template_source_loaders
@@ -295,13 +295,13 @@ def get_traceback_data(self):
295 295
     def get_traceback_html(self):
296 296
         "Return HTML version of debug 500 HTTP error page."
297 297
         t = Template(TECHNICAL_500_TEMPLATE, name='Technical 500 template')
298  
-        c = Context(self.get_traceback_data())
  298
+        c = Context(self.get_traceback_data(), use_l10n=False)
299 299
         return t.render(c)
300 300
 
301 301
     def get_traceback_text(self):
302 302
         "Return plain text version of debug 500 HTTP error page."
303 303
         t = Template(TECHNICAL_500_TEXT_TEMPLATE, name='Technical 500 template')
304  
-        c = Context(self.get_traceback_data(), autoescape=False)
  304
+        c = Context(self.get_traceback_data(), autoescape=False, use_l10n=False)
305 305
         return t.render(c)
306 306
 
307 307
     def get_template_exception_info(self):
16  tests/view_tests/tests/test_debug.py
@@ -5,6 +5,7 @@
5 5
 
6 6
 import inspect
7 7
 import os
  8
+import re
8 9
 import shutil
9 10
 import sys
10 11
 from tempfile import NamedTemporaryFile, mkdtemp, mkstemp
@@ -69,6 +70,21 @@ def test_view_exceptions(self):
69 70
             self.assertRaises(BrokenException, self.client.get,
70 71
                 reverse('view_exception', args=(n,)))
71 72
 
  73
+    def test_non_l10ned_numeric_ids(self):
  74
+        """
  75
+        Numeric IDs and fancy traceback context blocks line numbers shouldn't be localized.
  76
+        """
  77
+        with self.settings(DEBUG=True, USE_L10N=True):
  78
+            response = self.client.get('/views/raises500/')
  79
+            # We look for a HTML fragment of the form
  80
+            # '<div class="context" id="c38123208">', not '<div class="context" id="c38,123,208"'
  81
+            self.assertContains(response, '<div class="context" id="', status_code=500)
  82
+            match = re.search(b'<div class="context" id="(?P<id>[^"]+)">', response.content)
  83
+            self.assertFalse(match is None)
  84
+            id_repr = match.group('id')
  85
+            self.assertFalse(re.search(b'[^c\d]', id_repr),
  86
+                             "Numeric IDs in debug response HTML page shouldn't be localized (value: %s)." % id_repr)
  87
+
72 88
     def test_template_exceptions(self):
73 89
         for n in range(len(except_args)):
74 90
             try:
1  tests/view_tests/urls.py
@@ -49,6 +49,7 @@
49 49
     (r'raises400/$', views.raises400),
50 50
     (r'raises403/$', views.raises403),
51 51
     (r'raises404/$', views.raises404),
  52
+    (r'raises500/$', views.raises500),
52 53
 
53 54
     # i18n views
54 55
     (r'^i18n/', include('django.conf.urls.i18n')),
8  tests/view_tests/views.py
@@ -31,6 +31,14 @@ def callable():
31 31
     except Exception:
32 32
         return technical_500_response(request, *sys.exc_info())
33 33
 
  34
+def raises500(request):
  35
+    # We need to inspect the HTML generated by the fancy 500 debug view but
  36
+    # the test client ignores it, so we send it explicitly.
  37
+    try:
  38
+        raise Exception
  39
+    except Exception:
  40
+        return technical_500_response(request, *sys.exc_info())
  41
+
34 42
 def raises400(request):
35 43
     raise SuspiciousOperation
36 44
 

0 notes on commit 6c12cd1

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