Files
json-c/tests/test_json_parse_cli.test
T
huangwenbin 0e5a2d43f7 json_parse returned success when input ended while the tokener was
still waiting for more data, and also after read() failures.

Finalize the tokener at EOF with the terminating NUL so valid scalar
values can complete, while rejecting genuinely truncated input.

Also propagate read errors to the caller and add CLI regression tests.
2026-09-14 15:23:04 +08:00

40 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
# Common definitions
if test -z "$srcdir"; then
srcdir="${0%/*}"
test "$srcdir" = "$0" && srcdir=.
test -z "$srcdir" && srcdir=.
fi
. "$srcdir/test-defs.sh"
set -x -v
printf '%s' '"tenant=blue;note=CANARY_STACK_WINDOW_2026;status=ok"' > file1.dat
(printf '"' ; printf 'A%.0s' $(seq 1 16) ; echo 'e2' | xxd -r -p) > file2.dat
TESTNAME="${0##*/}"
TESTNAME="${TESTNAME%.test}"
( cat file1.dat ; cat file2.dat ) | run_output_test -o "${TESTNAME}" --exit 1 ../apps/json_parse -u -N -n -
_err=$?
printf '{' | "${top_builddir}/../apps/json_parse" -N -n - > /dev/null 2>&1
if test $? -eq 0; then
echo "ERROR: json_parse accepted incomplete input" 1>&2
_err=1
fi
printf '123' | "${top_builddir}/../apps/json_parse" -N -n - > /dev/null 2>&1
if test $? -ne 0; then
echo "ERROR: json_parse rejected valid EOF-terminated scalar input" 1>&2
_err=1
fi
"${top_builddir}/../apps/json_parse" -N -n - <&- > /dev/null 2>&1
if test $? -eq 0; then
echo "ERROR: json_parse returned success after read failure" 1>&2
_err=1
fi
exit $_err