jq icon indicating copy to clipboard operation
jq copied to clipboard

strftime produces corrupted characters in windows

Open baterflyrity opened this issue 7 months ago • 7 comments

Describe the bug Using strftime function in Windows produces unreadable symbols in console.

To Reproduce Taken from https://github.com/jqlang/jq/blob/693a7261e5ebccaf0c74fde0ac48700ba3d52f17/tests/optional.test#L16 and https://github.com/jqlang/jq/blob/693a7261e5ebccaf0c74fde0ac48700ba3d52f17/tests/jq.test#L1562:

$ echo 1435677542.822351 | jq "strftime(\"%A, %B %d, %Y\")"
"�������, ���� 30, 2015"

Using both windows 1251 and utf 8 encodings gives same corrupted output.

Expected behavior The output should be readable.

Environment (please complete the following information):

  • OS and Version: Windows 10 x64
  • jq version: jq-1.7-dirty

Additional context

Both files contain same test case.

baterflyrity avatar Dec 03 '23 10:12 baterflyrity

Huh weird, possibly to pipe it thru hexdump -C or possibly redirect to a file and attach? but maybe it will just show replacement characters hmm

wader avatar Dec 03 '23 11:12 wader

Did you try chcp 65001 ?

itchyny avatar Dec 03 '23 12:12 itchyny

Huh weird, possibly to pipe it thru hexdump -C or possibly redirect to a file and attach? but maybe it will just show replacement characters hmm

Sure. Here it is: jq#2961.txt

echo 1435677542.822351 | jq "strftime(\"%A, %B %d, %Y\")" > jq#2961.txt

22efbfbdefbfbdefbfbdefbfbdefbfbdefbfbdefbfbd2c20efbfbdefbfbdefbfbdefbfbd2033302c2032303135220d0a

Did you try chcp 65001 ?

Yes, of course. Same for any codepage.

$ chcp 65001
$ echo 1435677542.822351 | jq "strftime(\"%A, %B %d, %Y\")"
"�������, ���� 30, 2015"

baterflyrity avatar Dec 03 '23 13:12 baterflyrity

Managed to kind of produce it with wine (no windows dev setup atm) and jq-windows-amd64.exe

$ docker run --platform linux/amd64 -ti --rm debian:bookworm
$ apt-get update
$ apt-get install -y curl wine
$ curl -OLJ https://github.com/jqlang/jq/releases/download/jq-1.7/jq-windows-amd64.exe

# same with LC_ALL=ru_RU.UTF-8
$ LC_ALL=ru_RU.CP1251 wine jq-windows-amd64.exe -n '1435677542.822351 | strftime("%A, %B %d, %Y")'
<lots-of-warnings>
"???????, ???? 30, 2015"
$ LC_ALL=ru_RU.UTF-8 wine jq-windows-amd64.exe -n '1435677542.822351 | strftime("%A, %B %d, %Y")'
<lots-of-warnings>
"???????, ???? 30, 2015"

# default local (if i run locale is says "POSIX")
$ wine jq-windows-amd64.exe -n '1435677542.822351 | strftime("%A, %B %d, %Y")'
"Tuesday, June 30, 2015"

# swedish seems to work
$ LC_ALL=sv.SE.CP1251 wine jq-windows-amd64.exe -n '1435677542.822351 | strftime("%A, %B %d, %Y")'
"tisdag, juni 30, 2015"

No idea how compareable this is to a proper windows installation but maybe there is something with msys2 and some locales etc?

wader avatar Dec 03 '23 15:12 wader

I wonder if we have to make stdout binary on Windows. It seems like something is interpreting the output.

nicowilliams avatar Jan 17 '24 15:01 nicowilliams

I can not reproduce the issue with jq from msys2 https://packages.msys2.org/base/mingw-w64-jq

$ echo 1435677542.822351 | jq "strftime(\"%A, %B %d, %Y\")"
"Tuesday, June 30, 2015"

No locale variable set, system language is US English.

Biswa96 avatar Feb 13 '24 05:02 Biswa96

Seems like non-latin characters are corrupted.

baterflyrity avatar Feb 13 '24 08:02 baterflyrity