Repository navigation
pcre2_substitute: reset \Q literal mode for each replacement - #1065
Merged
NWilson merged 1 commit intoNov 6, 2026
Merged
Conversation
With PCRE2_SUBSTITUTE_EXTENDED, a \Q that is not closed by \E puts the rest
of the replacement in literal mode. The flag was declared outside the global
substitution loop, so it stayed set for the replacement of the next match, and
that replacement was copied as literal text, \Q included:
/x/g,replace=\Qabc,substitute_extended
xx gave abc\Qabc, not abcabc
Declare the flag inside the loop, next to the case-forcing state, which is
already reset for each match.
Tests were added to testinput2 and testoutput2.
Member
|
Thank you! I will review this soon. It certainly looks correct on the surface, and fixes a bug. |
NWilson
approved these changes
Nov 6, 2026
NWilson
left a comment
Member
There was a problem hiding this comment.
I like it! I think it's correct. Thank you.
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.
In
pcre2_substitute()withPCRE2_SUBSTITUTE_EXTENDED, a\Qnot closed by\Estayed set for the next match in global mode, so/x/g,replace=\Qabconxxgaveabc\Qabc. The flag now lives inside the global loop, next to the case-forcing state. Tests are in testinput2 and testoutput2.Verified:
RunTest.pytest 2 on Windows on all widths with JIT, andRunTeston Linux. Not available: the devcontainer presets, Valgrind, ManyConfigTests, MSVC, 32-bit, EBCDIC, autotools.