Skip to contentSkip to conversation

${var:-default} and ${var-default} append default value instead of discarding it when default contains multi-byte characters

PATCH New Grégory Pakosz 2 participants 2 messages Apr 23 – Apr 25

lore
Share & tools
lore
#0 lore raw

Hello,

It seems that Dash regressed (but I don't know when).

$ dash -c 'x=X; printf "before: %s (%d)\n" "$x" "${#x}"; x=${x:-↗};
printf "after: %s (%d)\n" "$x" "${#x}"'
before: ↗ (1)
after: X↗ (2)

I'm using Dash 0.5.13.2 on macOS, installed via Homebrew. The bug seems to be locale irrelevant.

Regards,
Grégory

#1 lore raw

PATCH 1/1 Drop multi-byte character in argstr when discard is on

Quoted 10 lines · Grégory Pakosz

It seems that Dash regressed (but I don't know when).

$ dash -c 'x=X; printf "before: %s (%d)\n" "$x" "${#x}"; x=${x:-↗};
printf "after: %s (%d)\n" "$x" "${#x}"'
before: ↗ (1)
after: X↗ (2)

I'm using Dash 0.5.13.2 on macOS, installed via Homebrew. The bug seems to be locale irrelevant.

Thank you. Please try this patch:

---8<---
The multi-byte character should not be copied to the destination in argstr if the discard flag is enabled. Fix it.

Fixes 6c44f4ee0c2b ("parser: Add support for multi-byte characters")
src/expand.c +2 -1
index bbf8454..76e67ce 100644
@@ -379,7 +379,8 @@ addquote:
 			if (c == CTLESC)
 				startloc += ml;
 			p += mb & 0xff;
-			expdest = stnputs(p, ml, expdest);
+			if (!(flag & EXP_DISCARD))
+				expdest = stnputs(p, ml, expdest);
 			p += mb >> 8;
 			break;
 		case CTLESC:
Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt