fix trimming with positional parameters (Closes: #48453)

This commit is contained in:
tg 2012-06-28 20:03:20 +00:00
parent dc5ae267ce
commit 0c3aed77e0
2 changed files with 25 additions and 3 deletions

15
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.544 2012/06/26 19:33:30 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.545 2012/06/28 20:03:17 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -1512,6 +1512,19 @@ expected-stdout:
0 = 1 .
111 = 3 .
---
name: expand-weird-3
description:
Check that trimming works with positional parameters (Debian #48453)
stdin:
A=9999-02
B=9999
echo 1=${A#$B?}.
set -- $A $B
echo 2=${1#$2?}.
expected-stdout:
1=02.
2=02.
---
name: eglob-bad-1
description:
Check that globbing isn't done when glob has syntax error

13
eval.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.119 2012/06/24 19:36:27 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.120 2012/06/28 20:03:20 tg Exp $");
/*
* string expansion
@ -369,7 +369,16 @@ expand(const char *cp, /* input word */
st->stype = stype;
st->base = Xsavepos(ds, dp);
st->f = f;
st->var = x.var;
if (x.var == &vtemp) {
st->var = tempvar();
st->var->flag &= ~INTEGER;
/* can't fail here */
setstr(st->var,
str_val(x.var),
KSH_RETURN_ERROR | 0x4);
} else
st->var = x.var;
st->quotew = st->quotep = quote;
/* skip qualifier(s) */
if (stype)