-
Notifications
You must be signed in to change notification settings - Fork 9
Implement matches override #319
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
Conversation
) bufbuild/protovalidate#382 --------- Signed-off-by: Sri Krishna <[email protected]>
| try: | ||
| m = re.search(pattern, text) | ||
| except re.error as ex: | ||
| return celpy.CELEvalError("match error", ex.__class__, ex.args) |
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.
does this match handling in celpy? or should we pull it out in an f-string + msg like the others?
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.
I tried to match what celpy was doing here yeah: See code here.
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.
ah, gotcha, my searching was not finding that code. works for me!
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).