Support CRLF line breaks in filters (#3274)

This commit is contained in:
itchyny authored and GitHub committed 2025-03-04 22:11:40 +09:00
1 parent b7a1201b72
commit c4e1fb08fb
4 files changed
+181 -165

No files matched your search

+15 -3
View File
@@ -189,6 +189,12 @@ cmp $d/out $d/expected
$JQ -V -h > $d/out 2>&1
cmp $d/out $d/expected
# CRLF line break support #1219
if ! x=$($JQ -n "$(printf '1\r\n+\r\n2')") || [ "$x" != '3' ]; then
echo 'CRLF line break support failed?' 1>&2
exit 1
fi
## Test streaming parser
## If we add an option to stream to the `import ... as $symbol;` directive
@@ -657,6 +663,12 @@ if ! x=$($JQ -cn '[
exit 1
fi
if ! x=$($JQ -cn "$(printf '[\r\n1,# comment\r\n2,# comment\\\r\ncomment\r\n3\r\n]')") \
|| [ "$x" != '[1,2,3]' ]; then
echo 'multiline comment with CRLF line breaks was not handled correctly'
exit 1
fi
# CVE-2023-50268: No stack overflow comparing a nan with a large payload
if $JQ -ne 'have_decnum'; then
$VALGRIND $Q $JQ '1 != .' <<\EOF >/dev/null
@@ -715,20 +727,20 @@ if ! $msys && ! $mingw; then
echo "Incorrectly formatted local time"
exit 1
fi
if ! r=$(TZ=Europe/Paris $JQ -rn '1731627341 | strflocaltime("%F %T %z %Z")') \
|| [ "$r" != "2024-11-15 00:35:41 +0100 CET" ]; then
echo "Incorrectly formatted local time"
exit 1
fi
if ! r=$(TZ=Europe/Paris $JQ -rn '1731627341 | strftime("%F %T %z %Z")') \
|| ( [ "$r" != "2024-11-14 23:35:41 +0000 UTC" ] \
&& [ "$r" != "2024-11-14 23:35:41 +0000 GMT" ] ); then
echo "Incorrectly formatted universal time"
exit 1
fi
if ! r=$(TZ=Etc/GMT+7 $JQ -nc '1731627341 | .,. | [strftime("%FT%T"),strflocaltime("%FT%T%z")]'
) \
|| [ "$r" != '["2024-11-14T23:35:41","2024-11-14T16:35:41-0700"]