Conversation
) bufbuild/protovalidate#382 --------- Signed-off-by: Sri Krishna <skrishna@buf.build>
Alfus
approved these changes
Jun 16, 2025
stefanvanburen
approved these changes
Jun 16, 2025
| try: | ||
| m = re.search(pattern, text) | ||
| except re.error as ex: | ||
| return celpy.CELEvalError("match error", ex.__class__, ex.args) |
Member
There was a problem hiding this comment.
does this match handling in celpy? or should we pull it out in an f-string + msg like the others?
Contributor
Author
There was a problem hiding this comment.
I tried to match what celpy was doing here yeah: See code here.
Member
There was a problem hiding this comment.
ah, gotcha, my searching was not finding that code. works for me!
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.
This implements an override of the
matchesfunction in celpy, which allows us to perform quasi-re2 operations. Since google-re2 does not yet support Python 3.13, we cannot use it in protovalidate-python.So, as a good compromise until then, we are simulating re2 behavior much like protovalidate-es does by failing on syntax not allowed in re2.
Note that protovalidate-es also parses regex flags at the beginning of regex patterns and applies them at the end. This is because ECMAScript regex does not support flags at the beginning. However, Python's re package does support this. So really all this does for now is to simply fail on invalid re2 syntax.
A future PR will add the ability for users to specify their own re2 engine via a config if they would like to override this behavior (which would not be a breaking change).