[PATCH] expand: Preserve MBCHAR in argstr when EXP_MBCHAR is set

Herbert Xu <[email protected]>
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
Martijn Dekker <[email protected]> wrote:
>
> ...'case' is broken for multi-byte characters. The following test script, when 
> saved in UTF-8, outputs 'BUG' instead of 'ok':
> 
> case "ρ" in
> ( "ρ" ) echo ok ;;
> ( * )   echo BUG; exit 1 ;;
> esac

Thanks for the report.  This patch should fix it:

---8<---
MBCHAR should be preserved in argstr if the EXP_MBCHAR bit is
set.  This broke case statements.

Reported-by: Martijn Dekker <[email protected]>
Fixes: 6c44f4ee0c2b ("parser: Add support for multi-byte characters")
Signed-off-by: Herbert Xu <[email protected]>
---
 src/expand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/expand.c b/src/expand.c
index 5285b79..93bb9a3 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -371,7 +371,7 @@ addquote:
 			c = (signed char)*p--;
 			mb = mbnext(p);
 			ml = (mb >> 8) - 2;
-			if (flag & QUOTES_ESC) {
+			if (flag & (QUOTES_ESC | EXP_MBCHAR)) {
 				length = (mb >> 8) + (mb & 0xff);
 				if (c == (char)CTLESC)
 					startloc += length;
-- 
2.39.2

-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.