Date: Sat, 3 Apr 2010 21:07:50 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r206147 - in head: bin/sh tools/regression/bin/sh/expansion Message-ID: <201004032107.o33L7os9000404@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Sat Apr 3 21:07:50 2010 New Revision: 206147 URL: http://svn.freebsd.org/changeset/base/206147 Log: sh: Allow quoting pattern match characters in ${v%pat} and ${v#pat}. Note that this depends on r206145 for allowing pattern match characters to have their special meaning inside a double-quoted expansion like "${v%pat}". PR: bin/117748 Exp-run done by: erwin (with some other sh(1) changes) Added: head/tools/regression/bin/sh/expansion/trim2.0 (contents, props changed) Modified: head/bin/sh/expand.c Modified: head/bin/sh/expand.c ============================================================================== --- head/bin/sh/expand.c Sat Apr 3 21:01:01 2010 (r206146) +++ head/bin/sh/expand.c Sat Apr 3 21:07:50 2010 (r206147) @@ -506,7 +506,9 @@ subevalvar(char *p, char *str, int strlo int amount; herefd = -1; - argstr(p, 0); + argstr(p, subtype == VSTRIMLEFT || subtype == VSTRIMLEFTMAX || + subtype == VSTRIMRIGHT || subtype == VSTRIMRIGHTMAX ? + EXP_CASE : 0); STACKSTRNUL(expdest); herefd = saveherefd; argbackq = saveargbackq; Added: head/tools/regression/bin/sh/expansion/trim2.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/regression/bin/sh/expansion/trim2.0 Sat Apr 3 21:07:50 2010 (r206147) @@ -0,0 +1,55 @@ +# $FreeBSD$ + +e= q='?' a='*' t=texttext s='ast*que?non' p='/et[c]/' w='a b c' b='{{(#)}}' +h='##' +failures='' +ok='' + +testcase() { + code="$1" + expected="$2" + oIFS="$IFS" + eval "$code" + IFS='|' + result="$#|$*" + IFS="$oIFS" + if [ "x$result" = "x$expected" ]; then + ok=x$ok + else + failures=x$failures + echo "For $code, expected $expected actual $result" + fi +} + +set -f +testcase 'set -- $s' '1|ast*que?non' +testcase 'set -- ${s%\?*}' '1|ast*que' +testcase 'set -- "${s%\?*}"' '1|ast*que' +testcase 'set -- ${s%\**}' '1|ast' +testcase 'set -- "${s%\**}"' '1|ast' +testcase 'set -- ${s%"$q"*}' '1|ast*que' +testcase 'set -- "${s%"$q"*}"' '1|ast*que' +testcase 'set -- ${s%"$a"*}' '1|ast' +testcase 'set -- "${s%"$a"*}"' '1|ast' +testcase 'set -- ${s%"$q"$a}' '1|ast*que' +testcase 'set -- "${s%"$q"$a}"' '1|ast*que' +testcase 'set -- ${s%"$a"$a}' '1|ast' +testcase 'set -- "${s%"$a"$a}"' '1|ast' +set +f + +testcase 'set -- "${b%\}}"' '1|{{(#)}' +# Parentheses are special in ksh, check that they can be escaped +testcase 'set -- "${b%\)*}"' '1|{{(#' +testcase 'set -- "${h#\#}"' '1|#' + +testcase 'set -- ${p%"${p#?}"}' '1|/' +testcase 'set -- ${p%"${p#??????}"}' '1|/etc' +testcase 'set -- ${p%"${p#???????}"}' '1|/etc/' +testcase 'set -- "${p%"${p#?}"}"' '1|/' +testcase 'set -- "${p%"${p#??????}"}"' '1|/et[c]' +testcase 'set -- "${p%"${p#???????}"}"' '1|/et[c]/' +testcase 'set -- ${p#"${p}"}' '0|' +testcase 'set -- "${p#"${p}"}"' '1|' +testcase 'set -- "${p#*\[}"' '1|c]/' + +test "x$failures" = x
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201004032107.o33L7os9000404>