coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

echo, printf: UTF-8 sensitivity in arguments

Open andrewliebenow opened this issue 1 year ago • 1 comments

❯ coreutils echo "$(coreutils printf 'A \xFF Z')"
error: invalid UTF-8 was detected in one or more arguments

Usage: coreutils echo [OPTIONS]... [STRING]...

For more information, try '--help'.

❯ /usr/bin/echo "$(coreutils printf 'A \xFF Z')"
A � Z
❯ coreutils printf "$(coreutils printf 'A \xFF Z')\n"
error: invalid UTF-8 was detected in one or more arguments

Usage: coreutils printf FORMATSTRING [ARGUMENT]...
       coreutils printf FORMAT [ARGUMENT]...
       coreutils printf OPTION

For more information, try '--help'.

❯ /usr/bin/printf "$(coreutils printf 'A \xFF Z')\n"
A � Z

I'm not sure if this is practically relevant. You can't print arbitrary binary data with echo/printf anyway, because the arguments are C strings (null terminated).

andrewliebenow avatar Oct 20 '24 18:10 andrewliebenow

Fixed in echo by https://github.com/uutils/coreutils/pull/6803 Not yet fixed in printf

andrewliebenow avatar Oct 20 '24 20:10 andrewliebenow