Skip to content

Commit

Permalink
Improve error messages when parsing integers beyond the 64-bit range (#…
Browse files Browse the repository at this point in the history
…236)

See: #235
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti authored Feb 21, 2025
1 parent 7bbce28 commit bd1b0e8
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a4140267959ae334d3ecf4
core https://github.com/sourcemeta/core 524815a71cf4941eb5f3bd13729cbd78c28469f6
core https://github.com/sourcemeta/core 5a3472c3b0102da83bb4a191cea743511b871a7a
hydra https://github.com/sourcemeta/hydra a67b879df800e834ed8a2d056f98398f7211d870
jsonbinpack https://github.com/sourcemeta/jsonbinpack c7bb7f4d903c3b6925b62ce2bb5b8d360e01ce84
blaze https://github.com/sourcemeta/blaze bf456d47dfd7fc51f077da268412735b4c6f9fa7
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ add_jsonschema_test_unix(validate/fail_schema_invalid_json)
add_jsonschema_test_unix(validate/fail_schema_non_schema)
add_jsonschema_test_unix(validate/fail_schema_unknown_dialect)
add_jsonschema_test_unix(validate/fail_trace)
add_jsonschema_test_unix(validate/fail_jsonl_bigint)
add_jsonschema_test_unix(validate/pass_trace)
add_jsonschema_test_unix(validate/pass_resolve)
add_jsonschema_test_unix(validate/pass_resolve_custom_extension)
Expand Down Expand Up @@ -149,6 +150,7 @@ add_jsonschema_test_unix(bundle/fail_resolve_duplicate)
add_jsonschema_test_unix(bundle/fail_resolve_invalid_json)
add_jsonschema_test_unix(bundle/fail_schema_invalid_json)
add_jsonschema_test_unix(bundle/fail_unknown_metaschema)
add_jsonschema_test_unix(bundle/fail_bigint)

# Inspect
add_jsonschema_test_unix(inspect/pass)
Expand All @@ -165,6 +167,7 @@ add_jsonschema_test_unix(lint/fail_lint)
add_jsonschema_test_unix(lint/fail_lint_yaml)
add_jsonschema_test_unix(lint/fail_lint_fix_yaml)
add_jsonschema_test_unix(lint/fail_lint_fix_yml)
add_jsonschema_test_unix(lint/fail_bigint)

# Encode
add_jsonschema_test_unix(encode/pass_schema_less)
Expand Down
37 changes: 37 additions & 0 deletions test/bundle/fail_bigint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

set -o errexit
set -o nounset

TMP="$(mktemp -d)"
clean() { rm -rf "$TMP"; }
trap clean EXIT

cat << 'EOF' > "$TMP/schema.json"
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com",
"$ref": "nested"
}
EOF

cat << 'EOF' > "$TMP/invalid.json"
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/nested",
"type": "integer",
"exclusiveMaximum": 9223372036854776000
}
EOF

"$1" bundle "$TMP/schema.json" \
--resolve "$TMP/invalid.json" --verbose 2>"$TMP/stderr.txt" \
&& CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1

cat << EOF > "$TMP/expected.txt"
error: The JSON value is not representable by the IETF RFC 8259 interoperable signed integer range at line 5 and column 23
$(realpath "$TMP")/invalid.json
EOF

diff "$TMP/stderr.txt" "$TMP/expected.txt"
26 changes: 26 additions & 0 deletions test/lint/fail_bigint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/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": "integer",
"maximum": 9223372036854776000
}
EOF

"$1" lint "$TMP/schema.json" >"$TMP/stderr.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1

cat << EOF > "$TMP/expected.txt"
error: The JSON value is not representable by the IETF RFC 8259 interoperable signed integer range at line 4 and column 14
$(realpath "$TMP")/schema.json
EOF

diff "$TMP/stderr.txt" "$TMP/expected.txt"
32 changes: 32 additions & 0 deletions test/validate/fail_jsonl_bigint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/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": "object"
}
EOF

cat << 'EOF' > "$TMP/instance.jsonl"
{ "foo": 1 }
{ "foo": 9223372036854776000 }
{ "foo": 3 }
EOF

"$1" validate "$TMP/schema.json" "$TMP/instance.jsonl" 2>"$TMP/stderr.txt" \
&& CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1

cat << EOF > "$TMP/expected.txt"
error: The JSON value is not representable by the IETF RFC 8259 interoperable signed integer range at line 2 and column 10
$(realpath "$TMP")/instance.jsonl
EOF

diff "$TMP/stderr.txt" "$TMP/expected.txt"
14 changes: 7 additions & 7 deletions vendor/core/cmake/FindBoostRegex.cmake

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 27 additions & 5 deletions vendor/core/src/core/json/include/sourcemeta/core/json_error.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/core/src/core/json/json.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/core/src/core/json/parser.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bd1b0e8

Please sign in to comment.