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
Unable to distinguish between bool and string in sprintf #6487
Comments
We could add a case ast.Boolean:
args[i] = bool(v) That would make Alternatively, we could do: case ast.Boolean:
args[i] = v which would produce: That is a bit messy since it leaks rego's internals. |
Indeed, and tbh I'm not sure leaking Go's internals is that much better. Passing A less leaky solution would be to use the type_name built-in function for the purpose of getting the name of a Rego value's type. |
💯 See also #4771. It's probably impossible to fix this in a backwards-compatible manner, though. We'd need to start deny-listing certain formats first, I guess... |
Didn't know about Would you be open to a PR that adds a blurb to the docs of |
Sure! I think the table is too cramped for details on that, but if we could add a blurb below the docs on the string functions, similar to how there's one below the functions for time, that could then later also be expanded with more gotchas, that'd be very useful! |
Fixes open-policy-agent#6487 Signed-off-by: Luiz Carvalho <lucarval@redhat.com>
Sounds like a good linter rule, too... |
Short description
When using
sprintf
, markers like%T
and%#v
produce the same exact output for the string"true"
and the booleantrue
. Both are reported as of type string.Steps To Reproduce
https://play.openpolicyagent.org/p/5HXqBdDKoX
Output:
Expected behavior
Like go, I would expect a marker like
%T
to evaluate tobool
if a boolean value is provided.Additional context
I'm writing a rule that expects a certain value to be the string
"true"
(I know... confusing). I want to be able to construct an error message that makes it clear to the user the value is not of type string.The text was updated successfully, but these errors were encountered: