raises: add missing | metacharacter to is_fully_escaped and unescape#14222
Merged
bluetech merged 1 commit intopytest-dev:mainfrom Mar 20, 2026
Merged
Conversation
Member
|
Similarly to your other PRs I commented on, could you please add a regression test to catch this issue? |
Contributor
Author
|
Added a regression test that verifies |
The pipe character is a regex metacharacter (alternation operator) but is_fully_escaped did not include it, so a match pattern like '^foo|bar$' would be wrongly identified as a fully-escaped literal. This causes rawmatch to be set incorrectly, leading to misleading diff output on match failure. Also add | to the unescape function's character class for consistency.
67f1959 to
1613a12
Compare
bluetech
approved these changes
Mar 20, 2026
Member
bluetech
left a comment
There was a problem hiding this comment.
I tweaked the test a bit and added a changelog.
Backport to 9.0.x: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 960ddc6 on top of patchback/backports/9.0.x/960ddc6f67d7a37b8390f260f8ded2049f8a28de/pr-14222 Backporting merged PR #14222 into main
🤖 @patchback |
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.
is_fully_escapedchecks whether a match pattern body (inside^...$) contains only escaped regex metacharacters, so pytest knows it can treat it as a literal string for diff output. The current metacharacter list is:This is missing
|, the regex alternation operator. A pattern like^foo|bar$would pass theis_fully_escapedcheck even though the|makes it a regex alternation rather than a literal. This causesrawmatchto be set to the unescaped valuefoo|bar, leading to a misleading diff in the failure message.The
unescapefunction has the same omission in its character class, so\|wouldn't be unescaped even if someone properly escaped it.This adds
|to both the metacharacter list inis_fully_escapedand the character class inunescape.