Skip to content
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

[Feature Request] Overload CEL matches function to support bytes values #268

Open
rodaine opened this issue Oct 21, 2024 · 0 comments
Open
Labels
Feature New feature or request

Comments

@rodaine
Copy link
Member

rodaine commented Oct 21, 2024

Feature description:

CEL supports <string>.matches(<string>) to apply an RE2 regular expression to strings. We expose this functionality in the custom/predefined constraints, as well as the underlying implementations of strings.pattern and bytes.pattern standard constraints.

Since the matches function only targets a string receiver, bytes.pattern first converts the value to a string before applying the regex. This only works if the bytes are a valid UTF8 string, failing with a runtime error within the CEL expression if it's not. This prevents the use of arbitrary byte sequences with the with regex.

To combat this, matches should be overloaded to support <bytes>.matches(<string>) which applies the regular expression without casting the receiver.

Problem it solves or use case:

Proper application of regular expressions against non-UTF8 bytes fields.

Proposed implementation or solution:

Add an overload to the custom CEL functions protovalidate requires of <bytes>.matches(<string>). This change can/should be upstreamed to the CEL project as well.

@rodaine rodaine added the Feature New feature or request label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant