sh: Fix '-' from quoted arithmetic in case/glob pattern range.
It does not make much sense to generate the '-' in a pattern bracket expression using arithmetic expansion, but it does not make sense to forbid it either. Try to avoid reprocessing the string if it is unnecessary.
This commit is contained in:
parent
c8da9163bf
commit
1b21b7fa89
@ -440,8 +440,15 @@ expari(const char *p, struct nodelist **restrict argbackq, int flag,
|
||||
fmtstr(expdest, DIGITS(result), ARITH_FORMAT_STR, result);
|
||||
adj = strlen(expdest);
|
||||
STADJUST(adj, expdest);
|
||||
if (!quoted)
|
||||
reprocess(expdest - adj - stackblock(), flag, VSNORMAL, 0, dst);
|
||||
/*
|
||||
* If this is quoted, a '-' must not indicate a range in [...].
|
||||
* If this is not quoted, splitting may occur.
|
||||
*/
|
||||
if (quoted ?
|
||||
result < 0 && begoff > 1 && flag & (EXP_GLOB | EXP_CASE) :
|
||||
flag & EXP_SPLIT)
|
||||
reprocess(expdest - adj - stackblock(), flag, VSNORMAL, quoted,
|
||||
dst);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ ${PACKAGE}FILES+= case18.0
|
||||
${PACKAGE}FILES+= case19.0
|
||||
${PACKAGE}FILES+= case20.0
|
||||
${PACKAGE}FILES+= case21.0
|
||||
${PACKAGE}FILES+= case22.0
|
||||
${PACKAGE}FILES+= cd1.0
|
||||
${PACKAGE}FILES+= cd2.0
|
||||
${PACKAGE}FILES+= cd3.0
|
||||
|
10
bin/sh/tests/builtins/case22.0
Normal file
10
bin/sh/tests/builtins/case22.0
Normal file
@ -0,0 +1,10 @@
|
||||
# $FreeBSD$
|
||||
|
||||
case 5 in
|
||||
[0"$((-9))"]) echo bad1 ;;
|
||||
esac
|
||||
|
||||
case - in
|
||||
[0"$((-9))"]) ;;
|
||||
*) echo bad2 ;;
|
||||
esac
|
Loading…
Reference in New Issue
Block a user