#872295 printf count utf-8 chars like arrow wrong

Package:
bash
Source:
bash
Description:
GNU Bourne Again SHell
Submitter:
"H.-Dirk Schmitt"
Date:
2024-04-29 13:36:03 UTC
Severity:
normal
#872295#5
Date:
2017-08-15 21:16:00 UTC
From:
To:
Package: coreutils
Version: 8.25-2

The printf command in bash (builtin) and corutils /usb/bin/printf have
an error in counting the length of a string, if a non-ascii character
is involved.
Example is the arrow - type Alt+I.

Try the following commands:
printf -v r "%-2s X\n" '→' ; echo ${#r} # prints 4
printf -v r "%-2s X\n" ' ' ; echo ${#r} # prints 5


The coreutils version of printf has the same misbehaviour.

#872295#10
Date:
2017-08-15 21:31:43 UTC
From:
To:
The bug leads to ugly output on the console if the data contains such
characters.

See the 3rd song in the following play queue listing:
--------------------------------------------------------------------
Pos. Artist                      Title                        Dur.
--------------------------------------------------------------------
  1. Bryan Adams                 I'm Ready                    4:26
  2. Toto                        Mrs. Johnson                 3:48
  3. The Doobie Brothers         Long Train Runnin’         3:39
  4. Three Dog Night             One                          3:02
  5. Norman Greenbaum            Spirit in the Sky            3:51
--------------------------------------------------------------------

#872295#15
Date:
2017-09-19 16:07:47 UTC
From:
To:
The problem has also another ugly effect in interactive shell usage
(here gnome-terminal).

I tried to rename a directory with utf-8 chars, but make a silly type
in the command. I tried to jump to the start of line with 'ctr+a'.
The cursors jumps some chars left of the command (inside the prompt
part).

example:
my Yirumav-Stay_in_Memory_기억에_머무르다/ Yiruma--Stay_in_Memory