Fix strftime/1 and strflocaltime/1 to allow an empty result (#3670)

These functions failed with "unknown system failure" whenever strftime()
returned 0 for a non-empty format, but 0 also means the format expands to
an empty string, as %p does in a locale without AM/PM.

Prepend a character to the format and trim it from the result, so that 0
can only mean the result is too long. Now 0 | strflocaltime("%p") gives
"" in fr_FR.UTF-8, and a result that is still too long fails with
"result too long" error instead. The size limit is unchanged.
This commit is contained in:
Doha Nam authored and GitHub committed 2026-10-13 16:47:58 +09:00
1 parent 80fc7a169d
commit 6b53f80311
3 files changed
+37 -10

No files matched your search

+9
View File
@@ -779,6 +779,15 @@ EOF
fi
fi
# strflocaltime/1 allows a format that expands to an empty string
l=fr_FR.UTF-8
if ! $msys && ! $mingw && [ -z "$(LC_ALL=$l date +%p 2>/dev/null)" ]; then
if ! out=$(LC_ALL=$l $VALGRIND $Q $JQ -n '0 | strflocaltime("%p")' 2>&1) || [ "$out" != '""' ]; then
echo "strflocaltime(\"%p\") in $l should output an empty string but got: $out"
exit 1
fi
fi
# Test syntax error messages of multiline filter (we can't test in jq.test)
if $VALGRIND $Q $JQ -n '[
try if .