Skip to content

Commit 4144f40

Browse files
posguy99McDutchie
andauthored
Fix expansion of multibyte character after $1 - $9, $?, etc (#102)
A multibyte character immediately following an expansion of a single-character name, e.g. $1 through $9, $?, $-, etc. was corrupted when in a UTF-8 locale, e.g.: $ set -- foo; echo "$1テスト" foo?スト Prior discussion: https://www.mail-archive.com/ast-users@lists.research.att.com/msg01060.html https://bugzilla.redhat.com/show_bug.cgi?id=1256495 src/cmd/ksh93/sh/macro.c: - Apply a Red Hat patch by Paulo Andrade that avoids calling fcmbget() if backtracking more than one byte might be required. src/cmd/ksh93/tests/basic.c: - Test "テスト" following expansion of "$1", "$?" and "$#". Co-authored-by: Martijn Dekker <martijn@inlv.org>
1 parent 02a14ff commit 4144f40

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎NEWS‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Any uppercase BUG_* names are modernish shell bug IDs.
88
- Fixed a bug that caused multidimensional associative arrays to be created
99
with an extra array member.
1010

11+
- Fixed a bug that caused the expansions of positional parameters $1 - $9,
12+
as well as special parameters such as $? and $-, to corrupt any multibyte
13+
characters immediately following the expansion if a UTF-8 locale is active.
14+
1115
2020-07-29:
1216

1317
- On a ksh compiled to use fork(2) to run external commands, a bug has been

‎src/cmd/ksh93/sh/macro.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,10 @@ static int varsub(Mac_t *mp)
15061506
default:
15071507
goto nosub;
15081508
}
1509-
c = fcmbget(&LEN);
1509+
if(type)
1510+
c = fcmbget(&LEN);
1511+
else
1512+
c = fcget();
15101513
if(type>M_TREE)
15111514
{
15121515
if(c!=RBRACE)

‎src/cmd/ksh93/tests/basic.sh‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,5 +615,18 @@ then actual=$(
615615
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
616616
fi
617617
618+
#"======
619+
# Expansion of multibyte characters after expansion of single-character names $1..$9, $?, $!, $-, etc.
620+
function exptest
621+
{
622+
print -r "$1テスト"
623+
print -r "$?テスト"
624+
print -r "$#テスト"
625+
}
626+
expect=$'fooテスト\n0テスト\n1テスト'
627+
actual=$(exptest foo)
628+
[[ $actual == "$expect" ]] || err_exit 'Corruption of multibyte char following expansion of single-char name' \
629+
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
630+
618631
# ======
619632
exit $((Errors<125?Errors:125))

0 commit comments

Comments
 (0)