-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix incorrect regex pattern in regex_replace_posix_groups #19827
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
base: main
Are you sure you want to change the base?
Fix incorrect regex pattern in regex_replace_posix_groups #19827
Conversation
The regex pattern was using (\d*) which matches zero or more digits,
causing a lone backslash to be incorrectly converted to ${}. Changed
to (\d+) which requires at least one digit, ensuring only actual POSIX
capture group references like \1, \2, etc. are converted to , .
Added unit tests to verify the correct behavior.
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.
Pull request overview
This PR fixes a bug in the regex_replace_posix_groups function where the regex pattern (\d*) incorrectly matched zero or more digits, causing a lone backslash \ to be transformed into ${}. The fix changes the pattern to (\d+) to require at least one digit.
Changes:
- Modified the regex pattern in
regex_replace_posix_groupsfrom(\d*)to(\d+)to match one or more digits - Added comprehensive unit tests to validate the fix and prevent regression
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
xanderbailey
left a comment
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.
Nice fix. Thanks for the PR. This looks correct to me but I don't have approval permissions!
The regex pattern was only matching single backslash (\1) but SQL string
literals with escaped backslashes pass through as double backslash (\\1).
Changed the pattern from (\\)(\d+) to \\{1,2}(\d+) to match 1 or 2
backslashes followed by digits, ensuring proper handling of SQL escaped
backreferences like 'X\\1Y'.
Added unit tests for the double backslash case.
|
Hi @GaneshPatil7517 Thank you for contribution. Please try to use the PR templates instead of the manual descriptions, it will allow the reviewers to easily understand the context. |
ok sir ill follow from you instruction.... |
|
FYI @shivbhatia10 -- is there any chance you would like to help review this PR too? |
The
regex_replace_posix_groupsmethod was using the pattern(\d*)to matchPOSIX capture group references like
\1. However,*matches zero or moredigits, which caused a lone backslash
\to incorrectly become${}.Changed to
(\d+)which requires at least one digit, fixing the issue.Added unit tests to validate correct behavior.