Repository navigation
🐛 fix(verbose): escape non-printable header text - #331
Merged
Merged
Conversation
A value holding a newline was split across lines of the --pytest-env-verbose header, and the continuation could read like a separate SET entry attributed to a real configuration file. The README's own MESSAGE="hello\nworld" example printed as two lines. Reported by Anthropic's OSS Scanner: ANT-2026-DEJB932Z. Fixes pytest-dev#322
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_format_actionsbuilt each line of the--pytest-env-verboseheader by interpolating the variable name, its value and the source path as they were (old lines). A value holding a newline was split across header lines, and the continuation could read like a separateSET,SKIPorUNSETentry attributed to a real configuration file. The variables the tests received were correct; only the header was wrong. 🐛 After this PR each action stays on one line. Fixes #322.Values reached the terminal unescaped
pytest writes every string a
pytest_report_headerhook returns to the terminal on its own line, so a newline inside one of them ends the line early. The README's own.envexample,MESSAGE="hello\nworld", printedSET MESSAGE=hellofollowed byworld (from …/.env)._format_actionsnow passes the name, the value and the source through_escape, which replaces every character thatstr.isprintablerejects with itsunicode_escapeform and leaves printable characters, non-ASCII letters included, as they are.Behavior changes
In the header a newline shows as
\n, a carriage return as\rand an escape character as\x1b. Output for values made of printable characters is unchanged, and so are the variables pytest-env sets. Anything that parses the header and expected a raw control character now sees the escaped form.Reported by Anthropic's OSS Scanner: ANT-2026-DEJB932Z.