open-policy-agent / opa

Open Policy Agent (OPA) is an open source, general-purpose policy engine.
https://www.openpolicyagent.org
Apache License 2.0
9.52k stars 1.32k forks source link

Improve `concat` to accept numeric values #6911

Open anderseknert opened 1 month ago

anderseknert commented 1 month ago

When trying to build JSON paths from an array of strings and numbers, concat will fail:

r := concat("/", ["path", 0, "foo"])
1 error occurred: policy.rego:5: rego_type_error: concat: invalid argument(s)
    have: (string, array<string, number, string>, ???)
    want: (delimiter: string, collection: any<array[string], set[string]>, output: string)

We can of course work around this by first converting all numbers in the array to strings, but it would be more convenient if concat treated numbers as strings in the first place. I can't think of any reason it shouldn't.

sunjh commented 4 weeks ago

Please assign to me, I can work on this, thanks!

sunjh commented 1 week ago

Working in progress. Will create pull request after the internal PR review.