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
topdown: Make *.is_valid function behavior more consistent #4844
topdown: Make *.is_valid function behavior more consistent #4844
Conversation
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.
This looks good. Any tests need to be added/updated. Also does this affect strict-builtin-errors
behavior?
I'll update the affected tests soon. This does not change |
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.
Thanks for picking this up!
perhaps it would be good to have a test with strict built in errors set to true, and assert the same behavior as when set to false?
Are there some types of errors we want to keep, even if they affect the true/false outputs? |
@philipaconrad OK! How does that work, given the functions return boolean and not errors now? If I provide e.g. an int to semver.is_valid, is that false without strict mode and an error with it on? |
It'll be |
Thanks @srenatus. This is what I wanted a test to assert. |
d1c8797
to
591535b
Compare
e4f13fa
to
d034006
Compare
Changes squashed, should be ready-for-merge. The old test cases that checked for builtin errors on the affected |
d034006
to
9ee5bd7
Compare
@philipaconrad not terribly important, but what I wanted was a test that kept the strict_error attribute set to true, and asserted that the value returned is still false. |
9ee5bd7
to
be94f17
Compare
This commit updates the `*.is_valid` functions to no longer produce errors when providing wrong-typed arguments. Instead, they will now return true/false for all inputs. Tests and WASM versions of these builtins have been updated to match the new behavior. Fixes open-policy-agent#4760. Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
be94f17
to
7539067
Compare
@anderseknert Done. I took the old |
This PR changes the behavior of the
*.is_valid
builtins to consistently return only true/false values, with no runtime/builtin errors. No docs changes should be required, since this is the documented behavior of these functions.The affected list of builtins:
Encoding:
base64.is_valid
json.is_valid
yaml.is_valid
GraphQL:
graphql.is_valid
Regex:
regex.is_valid
(already implements behavior)Semver:
semver.is_valid
Questionable additions to the list:
io.jwt.verifyX
functions?Fixes #4760.