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

Rule: sprintf-arguments-mismatch #1009

Closed
anderseknert opened this issue Aug 26, 2024 · 2 comments · Fixed by #1011
Closed

Rule: sprintf-arguments-mismatch #1009

anderseknert opened this issue Aug 26, 2024 · 2 comments · Fixed by #1011

Comments

@anderseknert
Copy link
Member

If too many or too few arguments are in the array provided to sprintf, OPA will return the "error" back in the string created.

> opa eval -f raw 'sprintf("%v", [1,2,3])'
1%!(EXTRA int=2, int=3)
opa eval -f raw 'sprintf("%v", [])'
%!v(MISSING)

It would be helpful if Regal did a count of the args in the string and compared it to the number of args in the array provided (if known), and flagged this as an issue.

@srenatus
Copy link
Member

% opa eval -f raw 'sprintf("%[1]v %[1]s", ["foo"])'
foo foo

It's annoying to fix this because we haven't specified what's OK and what is not, and the surface is just so large. But covering the 80% would certainly be useful.

@anderseknert
Copy link
Member Author

Yeah, good point! I'd say covering the "normal" cases is probably going to amount to somewhere closer to 99%... but perhaps people are more creative with sprintf than what I've seen.

Both "explicit argument indexes" (of which I learnt about just now), and %% which means "literally %" should be possible to account for... but perhaps there are more ways to have % not necessarily map 1:1 to a value.

@anderseknert anderseknert changed the title Rule: sprintf-argument-mismatch Rule: sprintf-arguments-mismatch Aug 27, 2024
anderseknert added a commit that referenced this issue Aug 27, 2024
Fixes #1009

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Aug 27, 2024
Fixes #1009

Signed-off-by: Anders Eknert <anders@styra.com>
srenatus pushed a commit to srenatus/regal that referenced this issue Oct 1, 2024
Fixes StyraInc#1009

Signed-off-by: Anders Eknert <anders@styra.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants