${var:-default} and ${var-default} append default value instead of discarding it when default contains multi-byte characters
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
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.
Reported-by Grégory Pakosz <[email protected]>
Fixes 6c44f4ee0c2b ("parser: Add support for multi-byte characters")
Signed-off-by Herbert Xu <[email protected]>
src/expand.c +2 -1
@@ -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