-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix segmentation fault when resolving a schema with a missing open brace
Signed-off-by: Juan Cruz Viotti <[email protected]>
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
TMP="$(mktemp -d)" | ||
clean() { rm -rf "$TMP"; } | ||
trap clean EXIT | ||
|
||
cat << 'EOF' > "$TMP/schema.json" | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "string" | ||
} | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/instance.json" | ||
"foo" | ||
EOF | ||
|
||
cat << 'EOF' > "$TMP/invalid.json" | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "https://example.com", | ||
"type": "string" | ||
} | ||
EOF | ||
|
||
"$1" validate "$TMP/schema.json" "$TMP/instance.json" \ | ||
--resolve "$TMP/invalid.json" 2>"$TMP/stderr.txt" \ | ||
&& CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << EOF > "$TMP/expected.txt" | ||
error: Failed to parse the JSON document at line 2 and column 3 | ||
$(realpath "$TMP")/invalid.json | ||
EOF | ||
|
||
diff "$TMP/stderr.txt" "$TMP/expected.txt" |