Skip to content

fix: detect whether to use jq -b correctly on Windows#15

Merged
taiki-e merged 2 commits intotaiki-e:mainfrom
chitoku-k:fix-windows
Jan 9, 2026
Merged

fix: detect whether to use jq -b correctly on Windows#15
taiki-e merged 2 commits intotaiki-e:mainfrom
chitoku-k:fix-windows

Conversation

@chitoku-k
Copy link
Copy Markdown
Contributor

This PR reverts #12 and applies a correct fix for #12 (comment).

The Bash bundled with Git for Windows removes trailing \r from value in variable assignment:

This patch results in the following different behavior which makes the comparison that tries to detect null\r always fail:

  • Original Bash:
    $ bash --version
    GNU bash, version 5.3.9(1)-release (x86_64-pc-linux-gnu)
    Copyright (C) 2025 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    
    This is free software; you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    
    $ foobar=$(printf '%s' $'foo\rbar')
    $ echo "${#foobar}"
    7
  • MSYS2 Bash:
    $ bash --version
    GNU bash, version 5.2.37(1)-release (x86_64-pc-msys)
    Copyright (C) 2022 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    
    This is free software; you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    
    $ foobar=$(printf '%s' $'foo\rbar')
    $ echo "${#foobar}"
    6

In order to correctly detect this case, I rewrote that part without variable assignment on MSYS2 Bash:

$ jq --version
jq-1.8.1

$ jq -r .a <<<'{}' | wc -c
6

$ jq -b -r .a <<<'{}' | wc -c
5

Copy link
Copy Markdown
Owner

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@taiki-e taiki-e merged commit 82a4639 into taiki-e:main Jan 9, 2026
41 checks passed
@chitoku-k chitoku-k deleted the fix-windows branch January 9, 2026 13:12
@taiki-e
Copy link
Copy Markdown
Owner

taiki-e commented Jan 11, 2026

Published in v3.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants