From b6942187683e0524c76f59c4eae6a5eb85e930fa Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sat, 2 Jul 2011 13:28:01 -1000 Subject: [PATCH] sh: Do not word split "${#parameter}". This is only a problem if IFS contains digits, which is unusual but valid. Obtained-from: FreeBSD SVN rev 221522 --- bin/sh/parser.c | 6 +++--- tools/regression/bin/sh/expansion/length6.0 | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 tools/regression/bin/sh/expansion/length6.0 diff --git a/bin/sh/parser.c b/bin/sh/parser.c index 74e7cbdc4f..952dcd37e9 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)parser.c 8.7 (Berkeley) 5/16/95 - * $FreeBSD: src/bin/sh/parser.c,v 1.106 2011/03/13 20:02:39 jilles Exp $ + * $FreeBSD: src/bin/sh/parser.c,v 1.107 2011/04/20 22:24:54 jilles Exp $ */ #include @@ -1571,8 +1571,8 @@ varname: pungetc(); } STPUTC('=', out); - if (subtype != VSLENGTH && (state[level].syntax == DQSYNTAX || - state[level].syntax == ARISYNTAX)) + if (state[level].syntax == DQSYNTAX || + state[level].syntax == ARISYNTAX) flags |= VSQUOTE; *(stackblock() + typeloc) = subtype | flags; if (subtype != VSNORMAL) { diff --git a/tools/regression/bin/sh/expansion/length6.0 b/tools/regression/bin/sh/expansion/length6.0 new file mode 100644 index 0000000000..166249aa19 --- /dev/null +++ b/tools/regression/bin/sh/expansion/length6.0 @@ -0,0 +1,8 @@ +# $FreeBSD: src/tools/regression/bin/sh/expansion/length6.0,v 1.1 2011/04/20 22:24:54 jilles Exp $ + +x='!@#$%^&*()[]' +[ ${#x} = 12 ] || echo bad 1 +[ "${#x}" = 12 ] || echo bad 2 +IFS=2 +[ ${#x} = 1 ] || echo bad 3 +[ "${#x}" = 12 ] || echo bad 4 -- 2.41.0