From cca1f7d18f2fa6721952645821ae429a0166d7e4 Mon Sep 17 00:00:00 2001 From: Emanuele Torre Date: Fri, 3 Nov 2023 19:53:33 +0100 Subject: Comment bug fixes, and fully support Tcl-style multiline comments * bugfix: comments were incorrectly being terminated by CR; for example jq -n $'1 #foo\r' fails to compile because the CR character terminates the comment, and CR is not a valid character in jq syntax. * improvement: comments fully support Tcl-style line continuation. Previously this was only "supported" in `-f' scripts, whose first line starts with "#!", and second line starts with # and ends with \, only for the comment on the second line, only for one extra line. * man: document comment syntax, which was previously undocumented. * tests: add regression tests for the bugfix, and some tests for line continuation in comments. --- tests/shtest | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests') diff --git a/tests/shtest b/tests/shtest index 11125478..dd007d15 100755 --- a/tests/shtest +++ b/tests/shtest @@ -579,6 +579,36 @@ if ( ! $msys && ! $mingw ) && locale -a > /dev/null; then fi fi +# Comments! +if ! x=$($JQ -n '123 # comment') || [ "$x" != 123 ]; then + echo 'comment did not work' + exit 1 +fi + +cr=$(printf \\r) +if ! x=$($JQ -n "1 # foo$cr + 2") || [ "$x" != 1 ]; then + echo 'regression: carriage return terminates comment' + exit 1 +fi + +if ! x=$($JQ -cn '[ + 1, + # foo \ + 2, + # bar \\ + 3, + 4, # baz \\\ + 5, \ + 6, + 7 + # comment \ + comment \ + comment +]') || [ "$x" != '[1,3,4,7]' ]; then + echo 'multiline comment was not handled correctly' + exit 1 +fi + # Allow passing the inline jq script before -- #2919 if ! r=$($JQ --args -rn -- '$ARGS.positional[0]' bar) || [ "$r" != bar ]; then echo "passing the inline script after -- didn't work" -- cgit v1.2.3