svn commit: r206147 - in head: bin/sh tools/regression/bin/sh/expansion

Jilles Tjoelker jilles at FreeBSD.org
Sat Apr 3 21:07:51 UTC 2010


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


More information about the svn-src-all mailing list