cel-python icon indicating copy to clipboard operation
cel-python copied to clipboard

Support for RE2

Open ddn0 opened this issue 1 year ago • 3 comments

It looks like the implementation of CEL matches, just calls Python re.search but Python re is not the same as RE2 as an example \z in RE2 should match the end of text, but \z in Python re is an invalid escape. The equivalent in Python re is \Z but that maps to an unsupported escape in RE2.

Example

echo '""' | python -m celpy 'string(this).matches("^\\z")'
# Should output true, but instead emits the error "re.error: bad escape \z at position 1"
echo '""' | python -m celpy 'string(this).matches("^\\Z")'
# Should be an error as \Z is not supported in RE2, but instead outputs true

Example of another CEL evaluator rejecting \Z but accepting \z

ddn0 avatar Mar 26 '24 05:03 ddn0

A pull request to replace re with https://pypi.org/project/re2/ would be welcome.

slott56 avatar May 21 '24 19:05 slott56

A pull request to replace re with https://pypi.org/project/re2/ would be welcome.

Done.

Please let me know what your style and testing preference is. I just made a quick scan of the repo before making my PR.

Also, re2 is a pretty old and looks unmaintained. I opted to use google-re2 instead.

ddn0 avatar May 24 '24 02:05 ddn0

There's a tox.ini to run a complete test suite.

The style is generally done by black.

You can also look at the GitHub workflows to see how the tox.ini runs.

slott56 avatar May 26 '24 17:05 slott56