Skip to content

gh-154470: Fix spurious ^J in pdb's colorized list command#154473

Open
ambv wants to merge 1 commit into
python:mainfrom
ambv:gh-154470-pdb-list-trailing-newline
Open

gh-154470: Fix spurious ^J in pdb's colorized list command#154473
ambv wants to merge 1 commit into
python:mainfrom
ambv:gh-154470-pdb-list-trailing-newline

Conversation

@ambv

@ambv ambv commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

pdb's list colorizes each source line with _colorize_code, which feeds it to _pyrepl.utils.disp_str. disp_str renders control characters in caret notation, so the trailing newline of each source line became a literal "^J". _print_lines only stripped the line after colorizing, and rstrip() cannot remove the embedded caret sequence.

Strip the line before colorizing, matching what where already does via format_stack_entry. Add a test that attaches with colorize enabled, runs list, and asserts no "^J" leaks into the source lines.

Broken by gh-146584.

pdb's `list` colorizes each source line with `_colorize_code`, which feeds it
to `_pyrepl.utils.disp_str`. `disp_str` renders control characters in caret
notation, so the trailing newline of each source line became a literal "^J".
`_print_lines` only stripped the line *after* colorizing, and rstrip() cannot
remove the embedded caret sequence.

Strip the line before colorizing, matching what `where` already does via
`format_stack_entry`. Add a test that attaches with colorize enabled, runs
`list`, and asserts no "^J" leaks into the source lines.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gaogaotiantian

Copy link
Copy Markdown
Member

I agree that the better way is to strip before colorize. However the is the test more complicated than it needs to be? We don't need remote pdb to trigger this issue - a local one would do. We missed it probably we normalized the white spaces in doctests?

BTW I'm aware of this issue a while ago but did not get the time to fix it. Planned to fix before 3.15.0 official release. Sorry about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants