﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37548	Technical 500 page shows wrong source lines when a module contains form feeds or Unicode line separators	Maddipatla Chatan		"ExceptionReporter._get_source() splits the source returned by a module loader with str.splitlines(). That also splits on form feeds (\x0c), \x1c-\x1e, \x85, \u2028 and \u2029, but Python only counts \n, \r\n and \r when numbering source lines. So after any of those characters, the context_line and the surrounding context shown on the technical 500 page are shifted.

The file fallback in the same method reads bytes and uses bytes.splitlines(), which only splits on \n, \r\n and \r, so it doesn't have this problem.

To reproduce, put this in a module (the third line is a single form feed character, which PEP 8 allows as a page break) and raise from it with DEBUG=True:

{{{
def one():
    pass
^L
def boom():
    x = 1
    raise ValueError(""here"")  # line 6
}}}

The frame reports lineno 6, but the highlighted context line is ""x = 1"" (line 5). A \u2028 inside a string literal shifts the lines the same way.

Splitting the loader source only on \n, \r\n and \r, like the file fallback does, fixes it.

Related: #13958, where splitlines() was introduced for \r line endings."	Bug	new	Error reporting	dev	Normal			Maddipatla Chatan	Unreviewed	0	0	0	0	0	0
