-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for 31456 -- replace
with optional matching group fails when there is no match
#31493
Closed
Closed
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8dd871a
Update regex.jl
tlienart e6abbda
Adding tests for replace (issue 31456)
tlienart 8012cb9
removing trailing whitespace in comment
tlienart cd82403
removing trailing whitespace in test
tlienart 254805e
Update pcre.jl
tlienart f416fd1
Update regex.jl
tlienart aed992e
Update util.jl
tlienart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look right --- isn't
match_data
always aPtr
?We might have to modify
substring_length_bynumber
to return 0 in this error case, but I'm not sure whether that's the best way to do it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok yes. Looking at the PCRE2 doc for substring (https://code.woboq.org/qt5/qtbase/src/3rdparty/pcre2/src/pcre2_substring.c.html) L315 onwards, it returns a PCRE2_ERROR_UNSET code (-55) when it can't find a match.
So locally I did the following:
substring_length_bynumber
as suggested with_write_capture
so that it doesn't go further when it has a length of 0 (otherwise the next PCRE function fails):And:
Should I try that in the PR or should I close it and let someone who knows more about PCRE take over?I've added that to the PR, feel free to close the PR if you think that's not the right approach, happy for someone more competent to do it (or tell me how it should be done)