Skip to content

Commit 0239960

Browse files
committed
builtins: update json.is_valid and yaml.is_valid for OPA v0.44.0
We're pulling the testcases only from 0.45.0 now; and use setup-opa for getting the binary that's used to generate the wasm module of the correct ABI version. Fixes #260. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
1 parent a675159 commit 0239960

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ jobs:
3131
node-version: [14.x, 16.x, 18.x]
3232
opa-version:
3333
- 0.30.2 # last version with ABI 1.1, 0.31.0+ has ABI 1.2
34-
- 0.41.0 # 0.35.0 is the first release with https://github.com/open-policy-agent/opa/pull/4055
34+
- 0.45.0 # 0.35.0 is the first release with https://github.com/open-policy-agent/opa/pull/4055
3535

3636
steps:
3737
- uses: actions/checkout@v3
3838

39-
- name: Checkout OPA v${{ matrix.opa-version }}
39+
- name: Checkout OPA v0.45.0 testcases
4040
uses: actions/checkout@v3
4141
with:
4242
repository: open-policy-agent/opa
43-
ref: v${{ matrix.opa-version }}
43+
ref: v0.45.0
4444
path: opa
4545

4646
- run: mkdir test/cases

src/builtins/json.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function isValidJSON(str) {
22
if (typeof str !== "string") {
3-
return;
3+
return false;
44
}
55
try {
66
JSON.parse(str);

src/builtins/yaml.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ function parse(str) {
3030
}
3131

3232
module.exports = {
33-
// is_valid is expected to return nothing if input is invalid otherwise
34-
// true/false for it being valid YAML.
35-
"yaml.is_valid": (str) => typeof str === "string" ? parse(str).ok : undefined,
33+
// is_valid is expected to return false if input is invalid; and true/false for it being valid YAML.
34+
"yaml.is_valid": (str) => typeof str === "string" && parse(str).ok,
3635
"yaml.marshal": (data) => yaml.stringify(data),
3736
"yaml.unmarshal": (str) => parse(str).result,
3837
};

0 commit comments

Comments
 (0)