Opened 15 years ago
Closed 12 years ago
#13958 closed Bug (fixed)
There is an error, when a source file with backslash-r returns is interpreted by the Python error report page.
| Reported by: | petrvanblokland | Owned by: | Steffen Zieger |
|---|---|---|---|
| Component: | Core (Other) | Version: | 1.2 |
| Severity: | Normal | Keywords: | |
| Cc: | me@… | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
There is an error, when a source file with backslash-r returns is interpreted by the Python error report page.
Due to a hard split on backslah-n, the lineno is out of range.
Also it is not clear what the name of the file is where this goes wrong.
Adding source = source.replace('\r', '\n') solves the problem, but maybe not structural enough.
Kind regards,
Petr van Blokland
buro@…
Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/django/core/servers/basehttp.py", line 279, in run
self.result = application(self.environ, self.start_response)
File "/Library/Python/2.5/site-packages/django/core/servers/basehttp.py", line 651, in __call__
return self.application(environ, start_response)
File "/Library/Python/2.5/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
response = self.get_response(request)
File "/Library/Python/2.5/site-packages/django/core/handlers/base.py", line 137, in get_response
return self.handle_uncaught_exception(request, resolver, exc_info)
File "/Library/Python/2.5/site-packages/django/core/handlers/base.py", line 157, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/Library/Python/2.5/site-packages/django/views/debug.py", line 58, in technical_500_response
html = reporter.get_traceback_html()
File "/Library/Python/2.5/site-packages/django/views/debug.py", line 109, in get_traceback_html
frames = self.get_traceback_frames()
File "/Library/Python/2.5/site-packages/django/views/debug.py", line 228, in get_traceback_frames
pre_context_lineno, pre_context, context_line, post_context = self._get_lines_from_file(filename, lineno, 7, loader, module_name)
File "/Library/Python/2.5/site-packages/django/views/debug.py", line 209, in _get_lines_from_file
context_line = source[lineno].strip('\n')
IndexError: list index out of range
Attachments (6)
Change History (20)
comment:1 by , 15 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 15 years ago
| Owner: | changed from to |
|---|
comment:3 by , 15 years ago
Hello!
I'm tying to reproduce this issue but I can't. Can you please add detailed instructions so we can reproduce?
I've confirmed that when opening a file with open(), python will correctly handle the different line terminators according to the platform, so after calling readlines() on a file descriptor returned with open() (using mode 'r'), the lines will only have the '\n' at the end, not the '\r\n'.
So maybe, this bug is caused by the call to 'loader.get_source' (django/views/debug.py(180)), but I can't confirm it without some more context.
comment:4 by , 15 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Closing invalid. Reporter hasn't responded to a request for more info. Please reopen if you can provide a test case as requested.
comment:5 by , 14 years ago
| Easy pickings: | unset |
|---|---|
| Has patch: | set |
| Resolution: | invalid |
| Severity: | → Normal |
| Status: | closed → reopened |
| Type: | → Uncategorized |
| UI/UX: | unset |
django.views.debug._get_lines_from_file uses readlines to split the lines of a file. This functions does not support the old Macintosh line break (\r) which is a valid line break in python code (http://docs.python.org/reference/lexical_analysis.html#physical-lines). So when an exception occurs in a file with Macintosh line break, the get_lines_from_file method will get an exception on the line
context_line = source[lineno].strip('\n')
since the source list will only contain one line with alot of '\r'.
This can be fixed by replacing the line
source = f.readlines()
with
source = f.read().splitlines()
comment:6 by , 14 years ago
| Easy pickings: | set |
|---|---|
| Type: | Uncategorized → Bug |
comment:7 by , 14 years ago
| Resolution: | → needsinfo |
|---|---|
| Status: | reopened → closed |
Closing as needsinfo. In order to accept this bug we need to know how to actually reproduce it, not just a statement of what looks wrong in the code and what to change.
by , 14 years ago
| Attachment: | patch_13958.diff added |
|---|
by , 14 years ago
| Attachment: | unittest_13958.diff added |
|---|
comment:8 by , 14 years ago
| Resolution: | needsinfo |
|---|---|
| Status: | closed → reopened |
Patch and unittest added
by , 14 years ago
| Attachment: | unittest_13958.2.diff added |
|---|
comment:9 by , 14 years ago
| Component: | Uncategorized → Core (Other) |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
The test case looks valid (even though the style could be improved).
utils.text.normalize_newlines might be handy here.
by , 13 years ago
| Attachment: | patch_13958.2.diff added |
|---|
by , 13 years ago
| Attachment: | unittest_13958.3.diff added |
|---|
comment:11 by , 13 years ago
| Status: | reopened → new |
|---|
by , 12 years ago
| Attachment: | 13958_fixed.diff added |
|---|
This patch is working for the current Django master
comment:12 by , 12 years ago
| Cc: | added |
|---|
comment:13 by , 12 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:14 by , 12 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Fixed formatting. Please use WikiFormatting and the preview button before submitting.