FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

sprintf builtin by andreaTP · Pull Request #43 · StyraOSS/opa-java-wasm · GitHub

sprintf builtin - #43

Merged
andreaTP merged 3 commits into
StyraOSS:mainfrom
andreaTP:impl-sprintf
Jan 15, 2025
Merged

sprintf builtin#43
andreaTP merged 3 commits into
StyraOSS:mainfrom
andreaTP:impl-sprintf

Conversation

Copy link
Copy Markdown
Collaborator

Implement the sprintf String builtin.

@anderseknert I was unable to find testcases to cover the edge cases, do you have a link to spare?

anderseknert left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There aren't that many tests for sprintf I'm afraid, as the OPA implementation simply mirrors the Go one. This was a mistake that has been problematic for all alternative implementations, as some things that Go's sprintf allows isn't feasible to implement in other languages. So the best thing is likely just to provide a best-effort implementation and to make it very clear that for anything non-trivial, the result is likely going to differ or not work at all.

The code looks good to me, but if you have somewhere where you've documented the supported built-is, it would be good to add a note about this there.

Copy link
Copy Markdown
Collaborator Author

So the best thing is likely just to provide a best-effort implementation and to make it very clear that for anything non-trivial, the result is likely going to differ or not work at all.

I see that it's already marked as "SDK-dependent":
https://www.openpolicyagent.org/docs/latest/policy-reference/#builtin-strings-sprintf

do you think we should do anything more?

it would be good to add a note about this there.

right, done, thanks for the reminder!

Comment thread Readme.md Outdated
At the moment the following builtins are supported(and, by default, automatically injected when needed):

- String
- `sprintf`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Good! What I alluded to before is that it would be really good to mention here how this built-in won't behave exactly as sprintf in OPA, and should ideally only be used for simple operations, like %s, %d and such.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for the feedback, I added a note, let me know how it reads 🙏

anderseknert left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Great! Thanks 👍

andreaTP merged commit 9967fe5 into StyraOSS:main Jan 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL