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.
This commit is contained in:
1 parent
f4929f3c19
commit
cca1f7d18f
7 files changed
+471
-298
No files matched your search
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user