[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ast-users
Subject:    [ast-users] Multibyte character string after $1-9 in ksh is not expanded correctly.
From:       Paulo_César_Pereira_de_Andrade <paulo.cesar.pereira.de.andrade
Date:       2015-08-24 18:11:29
Message-ID: CAHAq8pGXcjnxYc9waWurD6so-4w6qVk3BY9mSUsLXo1BoZXBNQ () mail ! gmail ! com
[Download RAW message or body]

Hi,

  I have this test case from a user, where ksh changed behavior
from ksh-20100621 to ksh-20120801.

  The test case is these 2 files:

$ cat test1.sh
#!/bin/ksh
echo "$1テスト"
echo "${1}テスト"
echo "$1test"

and

$ cat test2.sh
#!/bin/ksh
echo "$1テスト" | od -x
echo "${1}テスト" | od -x
echo "$1test" | od -x

  They output:
$ ksh ./test1.sh
�スト
テスト
test
$ ksh ./test2.sh
0000000 e386 b982 83e3 0a88
0000010
0000000 83e3 e386 b982 83e3 0a88
0000012
0000000 6574 7473 000a
0000005

  Previously ksh, in src/cmd/ksh93/sh/macro.c:varsub()
was:

    c = fcget();
    if(type>M_TREE)
...
    nulflg = 0;
    if(type && c==':')
...
    if(type)
...
    else
    {
        fcseek(-1);
        c=0;
    }
    if(c==':')  /* ${name:expr1[:expr2]} */

  The code in newer ksh is almost identical, with the
exception that instead of "c = fcget();" it starts with:

    c = fcmbget(&LEN);

that causes it to read 3 characters, but only "backtrack"
one character in the given test case.

  The attached patch corrects the problem, should be
simple enough, and only use the previous behavior when
the condition in the test case is met.

Thanks,
Paulo

["ksh-20120801-mb-after-argvar.patch" (text/x-patch)]

diff -up ksh-20120801/src/cmd/ksh93/sh/macro.c.orig ksh-20120801/src/cmd/ksh93/sh/macro.c
--- ksh-20120801/src/cmd/ksh93/sh/macro.c.orig	2015-08-24 14:29:58.602967855 -0300
+++ ksh-20120801/src/cmd/ksh93/sh/macro.c	2015-08-24 14:31:13.682850008 -0300
@@ -1479,7 +1479,10 @@ retry1:
 	    default:
 		goto nosub;
 	}
-	c = fcmbget(&LEN);
+	if(type)
+		c = fcmbget(&LEN);
+	else
+		c = fcget();
 	if(type>M_TREE)
 	{
 		if(c!=RBRACE)


_______________________________________________
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic