Skip to content
Myr

shtest

This file

Path

tests/shtest

1,016 lines · 32.3 KiB

Last changed by

landed by oscabriel6b53f80

History of this file

Take it

The walk stopped after 200 commits: lines older than fa6a2ff point at it.

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 1–6why, one step back
1#!/bin/sh -x
23. "${0%/*}/setup" "$@"45msys=false6mingw=false

Add Solaris support (#3515)Vladimír Marekbefore adoption9f778b4

line 7why, one step back
7sunos=false

Add FreeBSD and NetBSD CI (#3600)neilbefore adoptiondbbae0d

line 8why, one step back
8netbsd=false

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 9–11why, one step back
9case "$(uname -s)" in
10MSYS*) msys=true;;11MINGW*) mingw=true;;

Add Solaris support (#3515)Vladimír Marekbefore adoption9f778b4

line 12why, one step back
12SunOS*) sunos=true;;

Add FreeBSD and NetBSD CI (#3600)neilbefore adoptiondbbae0d

line 13why, one step back
13NetBSD*) netbsd=true;;

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 14–18why, one step back
14esac
1516JQ_NO_B=$JQ17JQ="$JQ -b"18

Add Solaris support (#3515)Vladimír Marekbefore adoption9f778b4

lines 19–23why, one step back
19# On Solaris, GNU tools are available in /usr/gnu. This script should prefer
20# them over the native tools, because the native versions may lack some21# command-line options the script relies on.22$sunos && PATH="/usr/gnu/bin:$PATH"23

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 24–28why, one step back
24PATH=$JQBASEDIR:$PATH $JQBASEDIR/tests/jq-f-test.sh > /dev/null
2526SHELL=/bin/sh27export SHELL28

fix: unset environment variables before shtests (#3283)SArpntbefore adoption9d6efec

lines 29–31why, one step back
29unset JQ_COLORS
30unset NO_COLOR31

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 32–61why, one step back
32if [ -f "$JQBASEDIR/.libs/libinject_errors.so" ]; then
33 # Do some simple error injection tests to check that we're handling34 # I/O errors correctly.35 (36 libinject=$JQBASEDIR/.libs/libinject_errors.so37 cd $d38 LD_PRELOAD=$libinject $JQ . /dev/null39 touch fail_read40 LD_PRELOAD=$libinject $JQ . fail_read && exit 241 touch fail_close42 LD_PRELOAD=$libinject $JQ . fail_close && exit 243 true44 )45fi4647printf 'a\0b\nc\0d\ne' > $d/input48$VALGRIND $Q $JQ -Rse '. == "a\u0000b\nc\u0000d\ne"' $d/input49$VALGRIND $Q $JQ -Rne '[inputs] == ["a\u0000b", "c\u0000d", "e"]' $d/input5051## Test constant folding52nref=$($VALGRIND $Q $JQ -n --debug-dump-disasm '"foo"' | wc -l)53for exp in '1+1' '1-1' '2*3' '9/3' '9%3' '9==3' '9!=3' \54 '9<3' '9>3' '9<=3' '9>=3' '1+2*3-4/5%6' '"foo" + "bar"'; do55 n=$($VALGRIND $Q $JQ -n --debug-dump-disasm "$exp" | wc -l)56 if [ $n -ne $nref ]; then57 echo "Constant expression folding didn't work: $exp"58 exit 159 fi60done61

Strip UTF-8 BOM at the start of each input file (#3657)itchynybefore adoptione001deb

lines 62–72why, one step back
62## Test UTF-8 BOM is stripped at the start of each input file
63printf '\357\273\277[{"foo": 1}\n,{"foo": 2}\n]\n' > $d/bom1.json64printf '\357\273\277[{"foo": 3}\n,{"foo": 4}\n]\n' > $d/bom2.json65$VALGRIND $Q $JQ -e '.[0].foo == 1' $d/bom1.json66$VALGRIND $Q $JQ -se '. == [[{"foo":1},{"foo":2}],[{"foo":3},{"foo":4}]]' $d/bom1.json $d/bom2.json67$VALGRIND $Q $JQ -ne '[inputs] == [[{"foo":1},{"foo":2}],[{"foo":3},{"foo":4}]]' $d/bom1.json $d/bom2.json68$VALGRIND $Q $JQ -ne '[inputs] == [[{"foo":1},{"foo":2}],[{"foo":3},{"foo":4}]]' $d/bom1.json - < $d/bom2.json69$VALGRIND $Q $JQ -Rne '[inputs] == ["[{\"foo\": 1}", ",{\"foo\": 2}", "]", "[{\"foo\": 3}", ",{\"foo\": 4}", "]"]' $d/bom1.json $d/bom2.json70$VALGRIND $Q $JQ -ne --slurpfile x $d/bom1.json '$x == [[{"foo":1},{"foo":2}]]'71$VALGRIND $Q $JQ -ne --rawfile x $d/bom1.json '$x == "[{\"foo\": 1}\n,{\"foo\": 2}\n]\n"'72

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 73–89why, one step back
73## Test JSON sequence support
74cat > $d/expected <<EOF75jq: ignoring parse error: Truncated value at line 2, column 576jq: ignoring parse error: Truncated value at line 2, column 2577jq: ignoring parse error: Truncated value at line 2, column 4178EOF79printf '1\0362 3\n[0,1\036[4,5]true"ab"{"c":4\036{}{"d":5,"e":6"\036false\n'|$VALGRIND $Q $JQ -ces --seq '. == [2,3,[4,5],true,"ab",{},false]' > /dev/null 2> $d/out80cmp $d/out $d/expected8182cat > $d/expected <<EOF83jq: ignoring parse error: Truncated value at line 2, column 584jq: ignoring parse error: Truncated value at line 2, column 2585jq: ignoring parse error: Truncated value at line 3, column 186EOF87printf '1\0362 3\n[0,1\036[4,5]true"ab"{"c":4\036{}{"d":5,"e":6"false\n\036null'|$VALGRIND $Q $JQ -ces --seq '. == [2,3,[4,5],true,"ab",{},null]' > /dev/null 2> $d/out88cmp $d/out $d/expected89

Skip to the next RS after a parse error in --seq mode (#3654)Michiel van Slobbebefore adoption80fc7a1

lines 90–97why, one step back
90# A syntax error skips the rest of the text, up to the next RS
91cat > $d/expected <<EOF92jq: ignoring parse error: Invalid numeric literal at line 1, column 8 (need RS to resync)93jq: ignoring parse error: Unmatched '}' at line 2, column 5 (need RS to resync)94EOF95printf '\036{"a":x,"b":7}\n\036[1,}2\n\0363\n' | $VALGRIND $Q $JQ -ces --seq '. == [3]' > /dev/null 2> $d/out96cmp $d/out $d/expected97

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 98–127why, one step back
98# Note that here jq sees no inputs at all but it still succeeds because
99# --seq ignores parse errors100cat > $d/expected <<EOF101jq: ignoring parse error: Unfinished abandoned text at EOF at line 1, column 4102EOF103printf '"foo' | $JQ -c --seq . > $d/out 2>&1104cmp $d/out $d/expected105106# with -e option should give 4 here as there's no valid output after107# ignoring parse errors with --seq.108printf '"foo' | $JQ -ce --seq . > $d/out 2>&1 || ret=$?109[ $ret -eq 4 ]110cmp $d/out $d/expected111112# Numeric values truncated by EOF are ignored113cat > $d/expected <<EOF114jq: ignoring parse error: Unfinished abandoned text at EOF at line 1, column 1115EOF116printf '1' | $JQ -c --seq . > $d/out 2>&1117cmp $d/out $d/expected118119cat > $d/expected <<EOF120jq: error (at <stdin>:1): Unfinished abandoned text at EOF at line 2, column 0121EOF122if printf '1\n' | $JQ -cen --seq '[inputs] == []' >/dev/null 2> $d/out; then123 printf 'Error expected but jq exited successfully\n' 1>&2124 exit 2125fi126cmp $d/out $d/expected127

Fix compiler warning `type-limits` in `found_string` (ref #2911) (#3263)itchynybefore adoption70e72ab

lines 128–141why, one step back
128# Test control characters for #2909
129cat > $d/expected <<EOF130jq: parse error: Invalid string: control characters from U+0000 through U+001F must be escaped at line 1, column 3131EOF132for i in 1 2 30 31; do133 if printf "\"$(printf '\\%03o' $i)\"" | $JQ '.' > $d/out 2>&1; then134 printf 'Error expected but jq exited successfully\n' 1>&2135 exit 2136 fi137 cmp $d/out $d/expected138done139printf '" ~\\u007f"\n' > $d/expected140printf "\"$(printf '\\%03o' 32 126 127)\"" | $JQ '.' > $d/out 2>&1141cmp $d/out $d/expected

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

line 142why, one step back
142

Reject raw NUL bytes in the parser instead of silently truncating tokens (#3606)augustbefore adoptionfbee8f4

lines 143–163why, one step back
143# Regression test for #3110: a raw NUL byte outside of a string must be a clean
144# parse error, not silently truncate the surrounding token. Previously145# `printf '12\0003'` printed 12 and dropped the trailing 3.146cat > $d/expected <<EOF147jq: parse error: Invalid character at line 1, column 3148EOF149if printf '12\0003' | $JQ '.' > $d/out 2>&1; then150 printf 'Error expected but jq exited successfully\n' 1>&2151 exit 2152fi153cmp $d/out $d/expected154# A NUL at the very start of the input is rejected too.155cat > $d/expected <<EOF156jq: parse error: Invalid character at line 1, column 1157EOF158if printf '\000' | $JQ '.' > $d/out 2>&1; then159 printf 'Error expected but jq exited successfully\n' 1>&2160 exit 2161fi162cmp $d/out $d/expected163

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 164–206why, one step back
164## Test --exit-status
165data='{"i": 1}\n{"i": 2}\n{"i": 3}\n'166printf "$data" | $JQ --exit-status 'select(.i==1)' > /dev/null 2>&1167printf "$data" | $JQ --exit-status 'select(.i==2)' > /dev/null 2>&1168printf "$data" | $JQ --exit-status 'select(.i==3)' > /dev/null 2>&1169ret=0170printf "$data" | $JQ --exit-status 'select(.i==4)' > /dev/null 2>&1 || ret=$?171[ $ret -eq 4 ]172ret=0173printf "$data" | $JQ --exit-status 'select(.i==2) | false' > /dev/null 2>&1 || ret=$?174[ $ret -eq 1 ]175printf "$data" | $JQ --exit-status 'select(.i==2) | true' > /dev/null 2>&1176177178# Regression test for #951179printf '"a\n' > $d/input180if $VALGRIND $Q $JQ -e . $d/input; then181 printf 'Issue #951 is back?\n' 1>&2182 exit 2183fi184185# Regression test for #2146186if echo "foobar" | $JQ .; then187 printf 'Issue #2146 is back?\n' 1>&2188 exit 1189elif [ $? -ne 5 ]; then190 echo "Invalid input had wrong error code" 1>&2191 exit 1192fi193194# Regression test for #2367; make sure to call jq twice195if ! echo '{"a": 1E9999999999}' | $JQ . | $JQ -e .a; then196 printf 'Issue #2367 is back?\n' 1>&2197 exit 1198fi199200# Regression test for #1534201echo "[1,2,3,4]" > $d/expected202printf "[1,2][3,4]" | $JQ -cs add > $d/out 2>&1203cmp $d/out $d/expected204printf "[1,2][3,4]\n" | $JQ -cs add > $d/out 2>&1205cmp $d/out $d/expected206

Fix behavior of `--slurp --stream` when input has no trailing newline character (#3279)itchynybefore adoption4e3088f

lines 207–213why, one step back
207# Regression test for #3273
208echo "[[[0],1],[[0]],[[0],2],[[0]]]" > $d/expected209printf "[1][2]" | $JQ -c -s --stream . > $d/out 2>&1210cmp $d/out $d/expected211printf "[1][2]\n" | $JQ -c -s --stream . > $d/out 2>&1212cmp $d/out $d/expected213

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 214–250why, one step back
214# Regression test for --raw-output0
215printf "a\0b\0" > $d/expected216printf '["a", "b"]' | $VALGRIND $Q $JQ --raw-output0 '.[]' > $d/out217cmp $d/out $d/expected218printf "a\0" > $d/expected219if printf '["a", "c\\u0000d", "b"]' | $VALGRIND $Q $JQ --raw-output0 '.[]' > $d/out; then220 echo "Should exit error on string containing NUL with --raw-output0" 1>&2221 exit 1222elif [ $? -ne 5 ]; then223 echo "Invalid error code" 1>&2224 exit 1225else226 cmp $d/out $d/expected227fi228229# Regression tests for #3194230echo 42 > $d/expected231$JQ -nn 42 > $d/out 2>&1232cmp $d/out $d/expected233234$JQ -nL. 42 > $d/out 2>&1235cmp $d/out $d/expected236$JQ -nL . 42 > $d/out 2>&1237cmp $d/out $d/expected238239$JQ -h > $d/expected 2>&1240$JQ -hV > $d/out 2>&1241cmp $d/out $d/expected242$JQ -h -V > $d/out 2>&1243cmp $d/out $d/expected244245$JQ -V > $d/expected 2>&1246$JQ -Vh > $d/out 2>&1247cmp $d/out $d/expected248$JQ -V -h > $d/out 2>&1249cmp $d/out $d/expected250

Support CRLF line breaks in filters (#3274)itchynybefore adoptionc4e1fb0

lines 251–256why, one step back
251# CRLF line break support #1219
252if ! x=$($JQ -n "$(printf '1\r\n+\r\n2')") || [ "$x" != '3' ]; then253 echo 'CRLF line break support failed?' 1>&2254 exit 1255fi256

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 257–426why, one step back
257## Test streaming parser
258259## If we add an option to stream to the `import ... as $symbol;` directive260## then we can move these tests into tests/all.test.261$VALGRIND $Q $JQ -c '. as $d|path(..) as $p|$d|getpath($p)|select((type|. != "array" and . != "object") or length==0)|[$p,.]' < "$JQTESTDIR/torture/input0.json" > $d/out0262$VALGRIND $Q $JQ --stream -c '.|select(length==2)' < "$JQTESTDIR/torture/input0.json" > $d/out1263diff $d/out0 $d/out1264265printf '["Unfinished JSON term at EOF at line 1, column 1",[0]]\n' > $d/expected266printf '[' | $VALGRIND $Q $JQ --stream-errors -c . > $d/out 2>&1267diff $d/out $d/expected268269270## XXX This test can be moved to tests/all.test _now_271clean=false272if which seq > /dev/null 2>&1; then273 # XXX We should try every prefix of input0.json, but that makes this274 # test very, very slow when run with valgrind, and the whole point275 # is to run it with valgrind.276 #277 #len=$(wc -c < "$JQTESTDIR/torture/input0.json")278 if [ -z "$VALGRIND" ]; then279 start=1280 end=$(wc -c < "$JQTESTDIR/torture/input0.json")281 else282 start=120283 end=151284 fi285 for i in $(seq $start $end); do286 dd "if=tests/torture/input0.json" bs=$i count=1 2>/dev/null |287 $VALGRIND $JQ -c . > $d/out0 2>$d/err || true288 if [ -n "$VALGRIND" ]; then289 grep '^==[0-9][0-9]*== ERROR SUMMARY: 0 errors' $d/err > /dev/null290 else291 tail -n1 -- "$d/err" | grep -Ei 'assert|abort|core' && false292 fi293294 dd "if=tests/torture/input0.json" bs=$i count=1 2>/dev/null |295 $VALGRIND $JQ -cn --stream 'fromstream(inputs)' > $d/out1 2>$d/err || true296 if [ -n "$VALGRIND" ]; then297 grep '^==[0-9][0-9]*== ERROR SUMMARY: 0 errors' $d/err > /dev/null298 else299 tail -n1 -- "$d/err" | grep -Ei 'assert|abort|core' && false300 fi301302 diff $d/out0 $d/out1303 done304else305 echo "Not doing torture tests"306fi307308## Regression test for issue #2378 assert when stream parse broken object pair309echo '{"a":1,"b",' | $JQ --stream > /dev/null 2> $d/err || true310grep 'Objects must consist of key:value pairs' $d/err > /dev/null311312## Regression tests for issue #2463 assert when stream parse non-scalar object key313echo '{{"a":"b"}}' | $JQ --stream > /dev/null 2> $d/err || true314grep "Expected string key after '{', not '{'" $d/err > /dev/null315echo '{"x":"y",{"a":"b"}}' | $JQ --stream > /dev/null 2> $d/err || true316grep "Expected string key after ',' in object, not '{'" $d/err > /dev/null317echo '{["a","b"]}' | $JQ --stream > /dev/null 2> $d/err || true318grep "Expected string key after '{', not '\\['" $d/err > /dev/null319echo '{"x":"y",["a","b"]}' | $JQ --stream > /dev/null 2> $d/err || true320grep "Expected string key after ',' in object, not '\\['" $d/err > /dev/null321322# debug, stderr323$VALGRIND $Q $JQ -n '"test", {} | debug, stderr' >/dev/null324$JQ -n -c -j '"hello\nworld", null, [false, 0], {"foo":["bar"]}, "\n" | stderr' >$d/out 2>$d/err325cat > $d/expected <<'EOF'326hello327worldnull[false,0]{"foo":["bar"]}328EOF329cmp $d/out $d/expected330cmp $d/err $d/expected331332# --arg, --argjson, $ARGS.named333$VALGRIND $JQ -n -c --arg foo 1 --argjson bar 2 '{$foo, $bar} | ., . == $ARGS.named' > $d/out334printf '{"foo":"1","bar":2}\ntrue\n' > $d/expected335cmp $d/out $d/expected336337# --slurpfile, --rawfile338$VALGRIND $JQ -n --slurpfile foo $JQBASEDIR/tests/modules/data.json \339 --rawfile bar $JQBASEDIR/tests/modules/data.json '{$foo, $bar}' > $d/out340cat > $d/expected <<'EOF'341{342 "foo": [343 {344 "this": "is a test",345 "that": "is too"346 }347 ],348 "bar": "{\n \"this\": \"is a test\",\n \"that\": \"is too\"\n}\n"349}350EOF351cmp $d/out $d/expected352353# --args, --jsonargs, $ARGS.positional354$VALGRIND $JQ -n -c --args '$ARGS.positional' foo bar baz > $d/out355printf '["foo","bar","baz"]\n' > $d/expected356cmp $d/out $d/expected357$VALGRIND $JQ -n -c --jsonargs '$ARGS.positional' null true '[]' '{}' > $d/out358printf '[null,true,[],{}]\n' > $d/expected359cmp $d/out $d/expected360$VALGRIND $JQ -n -c '$ARGS.positional' --args foo 1 --jsonargs 2 '{}' --args 3 4 > $d/out361printf '["foo","1",2,{},"3","4"]\n' > $d/expected362cmp $d/out $d/expected363$VALGRIND $JQ -n -c '$ARGS.positional' --args --jsonargs > $d/out364printf '[]\n' > $d/expected365cmp $d/out $d/expected366367## Regression test for issue #2572 assert when using --jsonargs and invalid JSON368$VALGRIND $JQ -n --jsonargs null invalid && EC=$? || EC=$?369if [ "$EC" -ne 2 ]; then370 echo "--jsonargs exited with wrong exit code, expected 2 got $EC" 1>&2371 exit 1372fi373# this tests the args_done code path "--"374$VALGRIND $JQ -n --jsonargs null -- invalid && EC=$? || EC=$?375if [ "$EC" -ne 2 ]; then376 echo "--jsonargs exited with wrong exit code, expected 2 got $EC" 1>&2377 exit 1378fi379380## Fuzz parser381382## XXX With a $(urandom) builtin we could move this test into tests/all.test383clean=false384if dd if=/dev/urandom bs=16 count=1024 > $d/rand 2>/dev/null; then385 # Have a /dev/urandom, good386 $VALGRIND $Q $JQ --seq . $d/rand >/dev/null 2>&1387 $VALGRIND $Q $JQ --seq --stream . $d/rand >/dev/null 2>&1388 dd if=/dev/urandom bs=16 count=1024 > $d/rand 2>/dev/null389 $VALGRIND $Q $JQ --seq . $d/rand >/dev/null 2>&1390 $VALGRIND $Q $JQ --seq --stream . $d/rand >/dev/null 2>&1391 dd if=/dev/urandom bs=16 count=1024 > $d/rand 2>/dev/null392 $VALGRIND $Q $JQ --seq . $d/rand >/dev/null 2>&1393 $VALGRIND $Q $JQ --seq --stream . $d/rand >/dev/null 2>&1394fi395clean=true396397## Test library/module system398399# Check handling of ~/.jq; these can't move into jq_test.c yet because400# they depend on $HOME401if [ "$(HOME="$mods/home1" $VALGRIND $Q $JQ -nr fg)" != foobar ]; then402 echo "Bug #479 appears to be back" 1>&2403 exit 1404fi405406if $msys || $mingw; then407 HOME_BAK=$HOME408 unset HOME409 if [ "$(USERPROFILE="$mods/home1" $VALGRIND $Q $JQ -nr foo)" != baz ]; then410 echo "Bug #3104 regressed (sourcing %USERPROFILE%/.jq on Windows)" 1>&2411 exit 1412 fi413 export HOME=$HOME_BAK414 unset HOME_BAK415fi416417if [ $(HOME="$mods/home1" $VALGRIND $Q $JQ --debug-dump-disasm -n fg | grep '^[a-z]' | wc -l) -ne 3 ]; then418 echo "Binding too many defs into program" 1>&2419 exit 1420fi421422if ! HOME="$mods/home2" $VALGRIND $Q $JQ -n 'include "g"; empty'; then423 echo "Mishandling directory ~/.jq" 1>&2424 exit 1425fi426

Detect circular module imports to prevent stack overflowitchynybefore adoptionf58787c

line 427why, one step back
427(

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 428–432why, one step back
428cd "$JQBASEDIR" # so that relative library paths are guaranteed correct
429if ! $VALGRIND $Q $JQ -L ./tests/modules -ne 'import "test_bind_order" as check; check::check==true'; then430 echo "Issue #817 regression?" 1>&2431 exit 1432fi

Detect circular module imports to prevent stack overflowitchynybefore adoptionf58787c

line 433why, one step back
433)

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

line 434why, one step back
434

Detect circular module imports to prevent stack overflowitchynybefore adoptionf58787c

line 435why, one step back
435(

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 436–438why, one step back
436cd "$JQBASEDIR"
437if ! $VALGRIND $Q $JQ -L tests/modules -ne 'import "test_bind_order" as check; check::check==true'; then438 echo "Issue #817 regression?" 1>&2

Detect circular module imports to prevent stack overflowitchynybefore adoptionf58787c

lines 439–458why, one step back
439 exit 1
440fi441)442443# CVE-2026-44777: Circular imports should be detected444if $VALGRIND $JQ -L "$mods" -ne 'import "cycle_a" as a; null' 2> $d/out; then445 echo "Mutual import should be rejected" 1>&2446 exit 1447fi448if ! grep -q "circular import" $d/out; then449 echo "Expected circular import error" 1>&2450 exit 1451fi452453if $VALGRIND $JQ -L "$mods" -ne 'import "cycle_self" as s; null' 2> $d/out; then454 echo "Self import should be rejected" 1>&2455 exit 1456fi457if ! grep -q "circular import" $d/out; then458 echo "Expected circular import error" 1>&2

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 459–481why, one step back
459 exit 1
460fi461462## Halt463464if ! $VALGRIND $Q $JQ -n halt; then465 echo "jq halt didn't work as expected" 1>&2466 exit 1467fi468if $VALGRIND $Q $VG_EXIT0 $JQ -n 'halt_error(1)'; then469 echo "jq halt_error(1) didn't work as expected" 1>&2470 exit 1471elif [ $? -ne 1 ]; then472 echo "jq halt_error(1) had wrong error code" 1>&2473 exit 1474fi475if $VALGRIND $Q $VG_EXIT0 $JQ -n 'halt_error(11)'; then476 echo "jq halt_error(11) didn't work as expected" 1>&2477 exit 1478elif [ $? -ne 11 ]; then479 echo "jq halt_error(11) had wrong error code" 1>&2480 exit 1481fi

Exit with the given status for negative `halt_error` codes (#3660)qodeliciousbefore adoption0404249

lines 482–490why, one step back
482for opt in '' -e; do
483 if $VALGRIND $Q $VG_EXIT0 $JQ $opt -n 'halt_error(-1)'; then484 echo "jq $opt halt_error(-1) didn't work as expected" 1>&2485 exit 1486 elif [ $? -ne 255 ]; then487 echo "jq $opt halt_error(-1) had wrong error code" 1>&2488 exit 1489 fi490done

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 491–523why, one step back
491if [ -n "$($VALGRIND $Q $JQ -n 'halt_error(1)' 2>&1)" ]; then
492 echo "jq halt_error(1) had unexpected output" 1>&2493 exit 1494fi495if [ -n "$($VALGRIND $Q $JQ -n '"xyz\n" | halt_error(1)' 2>/dev/null)" ]; then496 echo "jq halt_error(1) had unexpected output on stdout" 1>&2497 exit 1498fi499if [ "$($VALGRIND $Q $JQ -n '"xy" | halt_error(1)' 2>&1 || echo "z")" != "xyz" ]; then500 echo "jq halt_error(1) had unexpected output" 1>&2501 exit 1502fi503if [ "$($VALGRIND $Q $JQ -n '"x\u0000y\u0000z" | halt_error(1)' 2>&1 | tr '\0' '.')" != "x.y.z" ]; then504 echo "jq halt_error(1) had unexpected output" 1>&2505 exit 1506fi507if [ "$($VALGRIND $Q $JQ -n '{"a":"xyz"} | halt_error(1)' 2>&1)" != '{"a":"xyz"}' ]; then508 echo "jq halt_error(1) had unexpected output" 1>&2509 exit 1510fi511512# Check $JQ_COLORS513514## Default colors, null input515$JQ -Ccn . > $d/color516printf '\033[0;90mnull\033[0m\n' > $d/expect517cmp $d/color $d/expect518519## Set non-default color, null input520JQ_COLORS='4;31' $JQ -Ccn . > $d/color521printf '\033[4;31mnull\033[0m\n' > $d/expect522cmp $d/color $d/expect523

Dynamically allocate JQ_COLORS escapes for truecolor support (#3282)SArpntbefore adoptionaa977aa

lines 524–538why, one step back
524## Set implicit empty color, null input
525$JQ -Ccn . > $d/color526printf '\033[0;90mnull\033[0m\n' > $d/expect527cmp $d/color $d/expect528529## Set explicit empty color, null input530JQ_COLORS=':' $JQ -Ccn . > $d/color531printf '\033[mnull\033[0m\n' > $d/expect532cmp $d/color $d/expect533534## Extra colors, null input535JQ_COLORS='::::::::' $JQ -Ccn . > $d/color536printf '\033[mnull\033[0m\n' > $d/expect537cmp $d/color $d/expect538

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 539–585why, one step back
539## Default colors, complex input
540$JQ -Ccn '[{"a":true,"b":false},"abc",123,null]' > $d/color541{542 printf '\033[1;39m[\033[0m'543 printf '\033[1;39m{\033[0m'544 printf '\033[1;34m"a"\033[0m'545 printf '\033[1;39m:\033[0m'546 printf '\033[0;39mtrue\033[0m'547 printf '\033[1;39m,\033[0m'548 printf '\033[1;34m"b"\033[0m'549 printf '\033[1;39m:\033[0m'550 printf '\033[0;39mfalse\033[0m'551 printf '\033[1;39m}\033[0m'552 printf '\033[1;39m,\033[0m'553 printf '\033[0;32m"abc"\033[0m'554 printf '\033[1;39m,\033[0m'555 printf '\033[0;39m123\033[0m'556 printf '\033[1;39m,\033[0m'557 printf '\033[0;90mnull\033[0m'558 printf '\033[1;39m]\033[0m\n'559} > $d/expect560cmp $d/color $d/expect561562## Set non-default colors, complex input563JQ_COLORS='0;30:0;31:0;32:0;33:0;34:1;35:1;36:1;37' \564 $JQ -Ccn '[{"a":true,"b":false},"abc",123,null]' > $d/color565{566 printf '\033[1;35m[\033[0m'567 printf '\033[1;36m{\033[0m'568 printf '\033[1;37m"a"\033[0m'569 printf '\033[1;36m:\033[0m'570 printf '\033[0;32mtrue\033[0m'571 printf '\033[1;36m,\033[0m'572 printf '\033[1;37m"b"\033[0m'573 printf '\033[1;36m:\033[0m'574 printf '\033[0;31mfalse\033[0m'575 printf '\033[1;36m}\033[0m'576 printf '\033[1;35m,\033[0m'577 printf '\033[0;34m"abc"\033[0m'578 printf '\033[1;35m,\033[0m'579 printf '\033[0;33m123\033[0m'580 printf '\033[1;35m,\033[0m'581 printf '\033[0;30mnull\033[0m'582 printf '\033[1;35m]\033[0m\n'583} > $d/expect584cmp $d/color $d/expect585

Add more test cases for JQ_COLORS support (ref #3288)itchynybefore adoptiond3cf5ca

lines 586–609why, one step back
586## Set non-default colors only for literals, complex input
587JQ_COLORS='0;37:0;31:0;35:0;34:0;36' \588 $JQ -Ccn '[{"a":true,"b":false},"abc",123,null]' > $d/color589{590 printf '\033[1;39m[\033[0m'591 printf '\033[1;39m{\033[0m'592 printf '\033[1;34m"a"\033[0m'593 printf '\033[1;39m:\033[0m'594 printf '\033[0;35mtrue\033[0m'595 printf '\033[1;39m,\033[0m'596 printf '\033[1;34m"b"\033[0m'597 printf '\033[1;39m:\033[0m'598 printf '\033[0;31mfalse\033[0m'599 printf '\033[1;39m}\033[0m'600 printf '\033[1;39m,\033[0m'601 printf '\033[0;36m"abc"\033[0m'602 printf '\033[1;39m,\033[0m'603 printf '\033[0;34m123\033[0m'604 printf '\033[1;39m,\033[0m'605 printf '\033[0;37mnull\033[0m'606 printf '\033[1;39m]\033[0m\n'607} > $d/expect608cmp $d/color $d/expect609

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 610–656why, one step back
610## Default colors, complex input, indented
611$JQ -Cn '[{"a":true,"b":false},"abc",123,null]' > $d/color612{613 printf '\033[1;39m[\033[0m\n'614 printf ' \033[1;39m{\033[0m\n'615 printf ' \033[1;34m"a"\033[0m'616 printf '\033[1;39m:\033[0m '617 printf '\033[0;39mtrue\033[0m'618 printf '\033[1;39m,\033[0m\n'619 printf ' \033[1;34m"b"\033[0m'620 printf '\033[1;39m:\033[0m '621 printf '\033[0;39mfalse\033[0m\n'622 printf ' \033[1;39m}\033[0m'623 printf '\033[1;39m,\033[0m\n'624 printf ' \033[0;32m"abc"\033[0m'625 printf '\033[1;39m,\033[0m\n'626 printf ' \033[0;39m123\033[0m'627 printf '\033[1;39m,\033[0m\n'628 printf ' \033[0;90mnull\033[0m\n'629 printf '\033[1;39m]\033[0m\n'630} > $d/expect631cmp $d/color $d/expect632633## Set non-default colors, complex input, indented634JQ_COLORS='0;30:0;31:0;32:0;33:0;34:1;35:1;36:1;37' \635 $JQ -Cn '[{"a":true,"b":false},"abc",123,null]' > $d/color636{637 printf '\033[1;35m[\033[0m\n'638 printf ' \033[1;36m{\033[0m\n'639 printf ' \033[1;37m"a"\033[0m'640 printf '\033[1;36m:\033[0m '641 printf '\033[0;32mtrue\033[0m'642 printf '\033[1;36m,\033[0m\n'643 printf ' \033[1;37m"b"\033[0m'644 printf '\033[1;36m:\033[0m '645 printf '\033[0;31mfalse\033[0m\n'646 printf ' \033[1;36m}\033[0m'647 printf '\033[1;35m,\033[0m\n'648 printf ' \033[0;34m"abc"\033[0m'649 printf '\033[1;35m,\033[0m\n'650 printf ' \033[0;33m123\033[0m'651 printf '\033[1;35m,\033[0m\n'652 printf ' \033[0;30mnull\033[0m\n'653 printf '\033[1;35m]\033[0m\n'654} > $d/expect655cmp $d/color $d/expect656

Add more test cases for JQ_COLORS support (ref #3288)itchynybefore adoptiond3cf5ca

lines 657–683why, one step back
657## Set truecolor, complex input, indented
658JQ_COLORS=$(printf '38;2;%s:' \659 '255;173;173' '255;214;165' '253;255;182' '202;255;191' \660 '155;246;255' '160;196;255' '189;178;255' '255;198;255') \661 $JQ -Cn '[{"a":true,"b":false},"abc",123,null]' > $d/color662{663 printf '\033[38;2;160;196;255m[\033[0m\n'664 printf ' \033[38;2;189;178;255m{\033[0m\n'665 printf ' \033[38;2;255;198;255m"a"\033[0m'666 printf '\033[38;2;189;178;255m:\033[0m '667 printf '\033[38;2;253;255;182mtrue\033[0m'668 printf '\033[38;2;189;178;255m,\033[0m\n'669 printf ' \033[38;2;255;198;255m"b"\033[0m'670 printf '\033[38;2;189;178;255m:\033[0m '671 printf '\033[38;2;255;214;165mfalse\033[0m\n'672 printf ' \033[38;2;189;178;255m}\033[0m'673 printf '\033[38;2;160;196;255m,\033[0m\n'674 printf ' \033[38;2;155;246;255m"abc"\033[0m'675 printf '\033[38;2;160;196;255m,\033[0m\n'676 printf ' \033[38;2;202;255;191m123\033[0m'677 printf '\033[38;2;160;196;255m,\033[0m\n'678 printf ' \033[38;2;255;173;173mnull\033[0m\n'679 printf '\033[38;2;160;196;255m]\033[0m\n'680} > $d/expect681cmp $d/color $d/expect682683# Check invalid JQ_COLORS

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 684–685why, one step back
684echo 'Failed to set $JQ_COLORS' > $d/expect_warning
685$JQ -Ccn '[{"a":true,"b":false},"abc",123,null]' > $d/expect

Add more test cases for JQ_COLORS support (ref #3288)itchynybefore adoptiond3cf5ca

line 686why, one step back
686for colors in '/' '[30' '30m' '30:31m:32' '30:*:31' 'invalid'; do

Add Solaris support (#3515)Vladimír Marekbefore adoption9f778b4

lines 687–688why, one step back
687 export JQ_COLORS=$colors
688 $JQ -Ccn '[{"a":true,"b":false},"abc",123,null]' > $d/color 2>$d/warning

Add more test cases for JQ_COLORS support (ref #3288)itchynybefore adoptiond3cf5ca

lines 689–691why, one step back
689 cmp $d/color $d/expect
690 cmp $d/warning $d/expect_warning691done

Add Solaris support (#3515)Vladimír Marekbefore adoption9f778b4

line 692why, one step back
692unset JQ_COLORS

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 693–697why, one step back
693
694# Check $NO_COLOR695test_no_color=true696$msys && test_no_color=false697$mingw && test_no_color=false

Add Solaris support (#3515)Vladimír Marekbefore adoption9f778b4

line 698why, one step back
698$sunos && test_no_color=false

Add FreeBSD and NetBSD CI (#3600)neilbefore adoptiondbbae0d

lines 699–702why, one step back
699# NetBSD's script(1) intermittently loses the whole session output (the
700# output file comes back empty for fast commands about half the time), so701# the pty checks cannot run reliably there.702$netbsd && test_no_color=false

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 703–768why, one step back
703if $test_no_color && command -v script >/dev/null 2>&1; then
704 if script -qc echo /dev/null >/dev/null 2>&1; then705 faketty() { script -qec "$*" /dev/null; }706 else # macOS707 faketty() { script -q /dev/null "$@" /dev/null |708 sed 's/^\x5E\x44\x08\x08//'; }709 fi710711 faketty $JQ_NO_B -n . > $d/color712 printf '\033[0;90mnull\033[0m\r\n' > $d/expect713 od -tc $d/expect714 od -tc $d/color715 cmp $d/color $d/expect716 faketty env NO_COLOR= $JQ_NO_B -n . > $d/color717 printf '\033[0;90mnull\033[0m\r\n' > $d/expect718 od -tc $d/expect719 od -tc $d/color720 cmp $d/color $d/expect721 faketty env NO_COLOR=1 $JQ_NO_B -n . > $d/color722 printf 'null\r\n' > $d/expect723 od -tc $d/expect724 od -tc $d/color725 cmp $d/color $d/expect726 faketty env NO_COLOR=1 $JQ_NO_B -Cn . > $d/color727 printf '\033[0;90mnull\033[0m\r\n' > $d/expect728 od -tc $d/expect729 od -tc $d/color730 cmp $d/color $d/expect731fi732733# #2785734if $VALGRIND $Q $JQ -n -f "$JQTESTDIR/no-main-program.jq" > $d/out 2>&1; then735 echo "jq -f $JQTESTDIR/no-main-program.jq succeeded"736 exit 1737else738 EC=$?739 if [ $EC -eq 1 ]; then740 echo "jq -f $JQTESTDIR/no-main-program.jq failed with memory errors"741 exit 1742 fi743 if [ $EC -ne 3 ]; then744 echo "jq -f $JQTESTDIR/no-main-program.jq failed with wrong exit code ($EC)"745 exit 1746 fi747fi748cat > $d/expected <<EOF749jq: error: Top-level program not given (try ".")750jq: 1 compile error751EOF752if ! diff $d/expected $d/out; then753 echo "jq -f $JQTESTDIR/no-main-program.jq failed but its error message is not the expected one"754 exit 1755fi756757if ! $VALGRIND $Q $JQ -n -f "$JQTESTDIR/yes-main-program.jq" > $d/out 2>&1; then758 echo "jq -f $JQTESTDIR/yes-main-program.jq failed"759 exit 1760fi761762if ! $msys && ! $mingw && locales=$(locale -a); then763 { l=$(grep -Ev '^(C|LANG|POSIX|en)' | grep -Ei '\.utf-?8$' | head -n1) ;} \764<<EOF765$locales766EOF767 if [ -z "$l" ]; then768 echo "WARNING: Not testing localization"

shtest: skip locale test if date lacks locale support (#3583)pavel kuliakabefore adoptiondbcaa9d

lines 769–770why, one step back
769 elif [ "$(LC_ALL=C date +%a%b)" = "$(LC_ALL=$l date +%a%b)" ]; then
770 echo "WARNING: Date does not produce locale-dependent output for $l, skipping localization test"

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

line 771why, one step back
771 else

Fix localization test for time formatting functions (fix #3368) (#3409)itchynybefore adoptionc8017bf

line 772why, one step back
772 dt1=$(LC_ALL=$l date +'%a %d %b %Y at %H:%M:%S')

Add Solaris support (#3515)Vladimír Marekbefore adoption9f778b4

line 773why, one step back
773 dt2=$(LC_ALL=$l $JQ -nr 'now | strflocaltime("%a %d %b %Y at %H:%M:%S")')

Fix localization test for time formatting functions (fix #3368) (#3409)itchynybefore adoptionc8017bf

lines 774–776why, one step back
774 dt3=$(LC_ALL=$l date +'%a %d %b %Y at %H:%M:%S')
775 if [ "$dt1" != "$dt2" ] && [ "$dt2" != "$dt3" ]; then776 echo "jq does not honor LC_ALL environment variable ($dt1, $dt2, $dt3)"

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 777–781why, one step back
777 exit 1
778 fi779 fi780fi781782# strflocaltime/1 allows a format that expands to an empty string783l=fr_FR.UTF-8784if ! $msys && ! $mingw && [ -z "$(LC_ALL=$l date +%p 2>/dev/null)" ]; then785 if ! out=$(LC_ALL=$l $VALGRIND $Q $JQ -n '0 | strflocaltime("%p")' 2>&1) || [ "$out" != '""' ]; then786 echo "strflocaltime(\"%p\") in $l should output an empty string but got: $out"787 exit 1788 fi789fi790

Improve error messages to show problematic position in the filter (#3292)itchynybefore adoptionb733dfa

lines 791–813why, one step back
791# Test syntax error messages of multiline filter (we can't test in jq.test)
792if $VALGRIND $Q $JQ -n '[793 try if .794 then 1795 else 2796 catch ]' > $d/out 2>&1; then797 echo 'syntax error not detected'798 exit 1799fi800cat > $d/expected <<EOF801jq: error: syntax error, unexpected catch, expecting end or '|' or ',' at <top-level>, line 5, column 3:802 catch ]803 ^^^^^804jq: error: Possibly unterminated 'if' statement at <top-level>, line 2, column 7:805 try if .806 ^^^^807jq: error: Possibly unterminated 'try' statement at <top-level>, line 2, column 3:808 try if .809 ^^^^^^^^810jq: 3 compile errors811EOF812diff $d/out $d/expected813

Fix syntax error assertion failure (fix #3348) (#3350)itchynybefore adoptiona587ddc

lines 814–827why, one step back
814# Test syntax error messages when error happens at the end.
815if $VALGRIND $Q $JQ -n 'if816' > $d/out 2>&1; then817 echo 'syntax error not detected'818 exit 1819fi820cat > $d/expected <<EOF821jq: error: syntax error, unexpected end of file at <top-level>, line 1, column 3:822 if823 ^824jq: 1 compile error825EOF826diff $d/out $d/expected827

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 828–857why, one step back
828# Comments!
829if ! x=$($JQ -n '123 # comment') || [ "$x" != 123 ]; then830 echo 'comment did not work'831 exit 1832fi833834cr=$(printf \\r)835if ! x=$($JQ -n "1 # foo$cr + 2") || [ "$x" != 1 ]; then836 echo 'regression: carriage return terminates comment'837 exit 1838fi839840if ! x=$($JQ -cn '[841 1,842 # foo \843 2,844 # bar \\845 3,846 4, # baz \\\847 5, \848 6,849 7850 # comment \851 comment \852 comment853]') || [ "$x" != '[1,3,4,7]' ]; then854 echo 'multiline comment was not handled correctly'855 exit 1856fi857

Support CRLF line breaks in filters (#3274)itchynybefore adoptionc4e1fb0

lines 858–863why, one step back
858if ! x=$($JQ -cn "$(printf '[\r\n1,# comment\r\n2,# comment\\\r\ncomment\r\n3\r\n]')") \
859 || [ "$x" != '[1,2,3]' ]; then860 echo 'multiline comment with CRLF line breaks was not handled correctly'861 exit 1862fi863

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

lines 864–907why, one step back
864# Allow passing the inline jq script before -- #2919
865if ! r=$($JQ --args -rn -- '$ARGS.positional[0]' bar) || [ "$r" != bar ]; then866 echo "passing the inline script after -- didn't work"867 exit 1868fi869if ! r=$($JQ --args -rn 1 -- '$ARGS.positional[0]' bar) || [ "$r" != 1 ]; then870 echo "passing the inline script before -- didn't work"871 exit 1872fi873874# CVE-2023-50246: No heap overflow for '-10E-1000000001'875$VALGRIND $Q $JQ . <<\NUM876-10E-1000000001877NUM878879# test for --indent and --compact-output -- #1465880printf '[1,2]\n' > $d/expected881$JQ --compact-output -n "[1,2]" > $d/out882cmp $d/out $d/expected883884printf '[\n1,\n2\n]\n' > $d/expected885$JQ --indent 0 -n "[1,2]" > $d/out886cmp $d/out $d/expected887888printf '[\n 1,\n 2\n]\n' > $d/expected889$JQ --indent 1 -n "[1,2]" > $d/out890cmp $d/out $d/expected891892printf '[\n 1,\n 2\n]\n' > $d/expected893$JQ --indent 5 -n "[1,2]" > $d/out894cmp $d/out $d/expected895896printf '[\n{\n"a": 1\n}\n]\n' > $d/expected897$JQ --indent 0 -n "[{a:1}]" > $d/out898cmp $d/out $d/expected899900printf '[\n {\n "a": 1\n }\n]\n' > $d/expected901$JQ --indent 1 -n "[{a:1}]" > $d/out902cmp $d/out $d/expected903904printf '[\n {\n "a": 1\n }\n]\n' > $d/expected905$JQ --indent 6 -n "[{a:1}]" > $d/out906cmp $d/out $d/expected907

fix: populate timezone data when formatting time (#3203)Marcin Serwinbefore adoption6d8e9f9

lines 908–914why, one step back
908if ! $msys && ! $mingw; then
909 # Test handling of timezones -- #2429, #2475910 if ! r=$(TZ=Asia/Tokyo $JQ -rn '1731627341 | strflocaltime("%F %T %z %Z")') \911 || [ "$r" != "2024-11-15 08:35:41 +0900 JST" ]; then912 echo "Incorrectly formatted local time"913 exit 1914 fi

Support CRLF line breaks in filters (#3274)itchynybefore adoptionc4e1fb0

line 915why, one step back
915

fix: populate timezone data when formatting time (#3203)Marcin Serwinbefore adoption6d8e9f9

lines 916–920why, one step back
916 if ! r=$(TZ=Europe/Paris $JQ -rn '1731627341 | strflocaltime("%F %T %z %Z")') \
917 || [ "$r" != "2024-11-15 00:35:41 +0100 CET" ]; then918 echo "Incorrectly formatted local time"919 exit 1920 fi

Support CRLF line breaks in filters (#3274)itchynybefore adoptionc4e1fb0

line 921why, one step back
921

Test daylight time for strflocaltime (#3323)Steven Ihdebefore adoption77d23e9

lines 922–928why, one step back
922 # Test when DST is in effect: #1912
923 if ! r=$(TZ=Europe/Paris $JQ -rn '1750500000 | strflocaltime("%F %T %z %Z")') \924 || [ "$r" != "2025-06-21 12:00:00 +0200 CEST" ]; then925 echo "Incorrectly formatted local time"926 exit 1927 fi928

fix: populate timezone data when formatting time (#3203)Marcin Serwinbefore adoption6d8e9f9

lines 929–934why, one step back
929 if ! r=$(TZ=Europe/Paris $JQ -rn '1731627341 | strftime("%F %T %z %Z")') \
930 || ( [ "$r" != "2024-11-14 23:35:41 +0000 UTC" ] \931 && [ "$r" != "2024-11-14 23:35:41 +0000 GMT" ] ); then932 echo "Incorrectly formatted universal time"933 exit 1934 fi

Support CRLF line breaks in filters (#3274)itchynybefore adoptionc4e1fb0

line 935why, one step back
935

fix: copy the string returned by getenv (#3264)Marcin Serwinbefore adoptionf3d4c11

lines 936–942why, one step back
936 if ! r=$(TZ=Etc/GMT+7 $JQ -nc '1731627341 | .,. | [strftime("%FT%T"),strflocaltime("%FT%T%z")]'
937) \938 || [ "$r" != '["2024-11-14T23:35:41","2024-11-14T16:35:41-0700"]939["2024-11-14T23:35:41","2024-11-14T16:35:41-0700"]' ]; then940 echo "strftime or strftimelocal are not pure functions"941 exit 1942 fi

fix: populate timezone data when formatting time (#3203)Marcin Serwinbefore adoption6d8e9f9

lines 943–944why, one step back
943fi
944

Limit number of function parameters and definitions to prevent SEGV (#3460)Ze Shengbefore adoptiona2741ee

lines 945–971why, one step back
945# Test ARG_NEWCLOSURE overflow protection (issue #3458)
946# Test 1: Too many function parameters (4097 params triggers the limit)947echo "Testing function parameter limit..."948cat > $d/expected <<EOF949jq: error: too many function parameters or local function definitions (max 4095)950jq: 1 compile error951EOF952$JQ -rn '"def f(\([range(4097) | "a\(.)"] | join(";"))): .; f(\([range(4097)] | join(";")))"' > $d/prog.jq953$JQ -nf $d/prog.jq 2> $d/out && {954 echo "Expected compile error for too many parameters"955 exit 1956}957diff $d/out $d/expected958959# Test 2: Too many local functions (4097 functions triggers the limit)960echo "Testing local function limit..."961cat > $d/expected <<EOF962jq: error: too many function parameters or local function definitions (max 4095)963jq: 1 compile error964EOF965$JQ -rn '"\([range(4097) | "def f\(.): \(.)"] | join("; ")); \([range(4097) | "f\(.)"] | join(" + "))"' > $d/prog.jq966$JQ -nf $d/prog.jq 2> $d/out && {967 echo "Expected compile error for too many local functions"968 exit 1969}970diff $d/out $d/expected971

Fix assertion failure on too many parameters in a nested function (#3663)itchynybefore adoptiona5323a3

lines 972–985why, one step back
972# Test 3: Too many function parameters in a nested function (issue #3661)
973echo "Testing function parameter limit in a nested function..."974cat > $d/expected <<EOF975jq: error: function has too many parameters (max 4095)976jq: error: too many function parameters or local function definitions (max 4095)977jq: 2 compile errors978EOF979$JQ -rn '"def g(\([range(4097) | "a\(.)"] | join(";"))): .; def f: g(\([range(4097)] | join(";"))); f"' > $d/prog.jq980$JQ -nf $d/prog.jq 2> $d/out && {981 echo "Expected compile error for too many parameters in a nested function"982 exit 1983}984diff $d/out $d/expected985

Fix NUL truncation in the JSON parseritchynybefore adoption6374ae0

lines 986–991why, one step back
986# CVE-2026-33948: No NUL truncation in the JSON parser
987if printf '{}\x00{}' | $JQ >/dev/null 2> /dev/null; then988 printf 'Error expected but jq exited successfully\n' 1>&2989 exit 1990fi991

Fix NUL truncation in program files loaded with -fitchynybefore adoption5a015de

lines 992–998why, one step back
992# CVE-2026-41256: No NUL truncation in program files loaded with -f
993printf '.\x00invalid' > "$d/nul_prog.jq"994if echo '42' | $JQ -f "$d/nul_prog.jq" >/dev/null 2>/dev/null; then995 printf 'Error expected for program file with NUL bytes\n' 1>&2996 exit 1997fi998

Reject embedded NUL bytes in module import pathsitchynybefore adoption9d223f1

lines 999–1015why, one step back
999# CVE-2026-43895: No NUL bytes in module/data import paths
1000printf 'import "a\\u0000b" as $x; .' > "$d/nul_import.jq"1001if $JQ -nf "$d/nul_import.jq" >/dev/null 2>/dev/null; then1002 printf 'Error expected for import path with NUL bytes\n' 1>&21003 exit 11004fi1005printf 'include "a\\u0000b"; .' > "$d/nul_include.jq"1006if $JQ -nf "$d/nul_include.jq" >/dev/null 2>/dev/null; then1007 printf 'Error expected for include path with NUL bytes\n' 1>&21008 exit 11009fi1010printf '"a\\u0000b" | modulemeta' > "$d/nul_modulemeta.jq"1011if $JQ -nf "$d/nul_modulemeta.jq" >/dev/null 2>/dev/null; then1012 printf 'Error expected for modulemeta with NUL bytes\n' 1>&21013 exit 11014fi1015

website: remove unused root path on building website (#3248)itchynybefore adoptionfa6a2ff

line 1016why, one step back
1016exit 0