diff mbox series

expand: Preserve MBCHAR in argstr when EXP_MBCHAR is set

Message ID ZoUtNluFpgNqGzXB@gondor.apana.org.au (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series expand: Preserve MBCHAR in argstr when EXP_MBCHAR is set | expand

Commit Message

Herbert Xu July 3, 2024, 10:51 a.m. UTC
Martijn Dekker <martijn@inlv.org> 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 <martijn@inlv.org>
Fixes: 6c44f4ee0c2b ("parser: Add support for multi-byte characters")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
 src/expand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

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;