-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Number literals with leading zeros cause issues in JSON marshaling #2947
Comments
Thanks for reporting this. Can you share your policy, or the part of it that's troubling here, in case it's clearly isolated and known? |
Thanks! @sedooe I think I found the cause. The policy file was similar to the following.
It was a bug in the policy writing. but it's really hard to debug based on the error message. Is it possible to have the compliant more readable? Thanks. |
With your example code in
That output is the same I'd get when running |
One more thing I forgot to mention is that the error only occurred when there were 2 layers' (may be more than 1 layer) folders, as following
|
At its core, https://play.golang.org/p/NufrdsAa1lg replicates what we're seeing. The problem here is that a policy containing |
Do you mean, "is NOT accepted at all", right? Thanks @srenatus ! |
No I think this is a valid problem. I could not replicate what you saw with PUTing the policy vs. loading it from the command line, but the fact that you can store a policy that cannot be marshalled to JSON is a bug. 🐛 |
Underlying this is the fact that we're using I think this boils down to deciding what we want to support, and fixing the problem accordingly. I'm leaning towards not allowing leading zeros in number literals. |
@srenatus Hm, so the policy code itself is kinda right, it would do what it suppose to, just the writing We are in an agreement there is a bug there. Thanks you for digging into it. |
I took the liberty of renaming the issue to make it a little more focused, hope you don't mind. Thanks again for bringing this up! |
Sure, thanks @srenatus. |
This looks like an issue in the scanner. It shouldn't be scanning number literals with leading zeros (that's not valid JSON). We don't support non-decimal numbers so this should be rejected immediately when the policy is tokenized. |
Additional checks for leading 0's are now part of the *Parser.parseNumber()'s validations, prior to parsing. Fixes open-policy-agent#2947 Signed-off-by: Laurence Cartwright <me@lcartwright.com>
Additional checks for leading 0's are now part of the *Parser.parseNumber()'s validations, prior to parsing. Fixes #2947 Signed-off-by: Laurence Cartwright <me@lcartwright.com>
Expected Behavior
Run OPA server, specifying the policies
Then list all policies
Actual Behavior
Steps to Reproduce the Problem
Got the following compliant
Additional Info
I am wondering whether there are any requirements/dependencies on the policy file or anything else. Thanks.
The text was updated successfully, but these errors were encountered: