bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 4/4] gnulib-tool: faster string handling for Posix shells.


From: Bruno Haible
Subject: Re: [PATCH 4/4] gnulib-tool: faster string handling for Posix shells.
Date: Sun, 18 Jan 2009 04:09:24 +0100
User-agent: KMail/1.9.9

Ralf Wildenhues wrote:
> > +# func_remove_prefix var prefix
> > +# removes the given prefix from the value of the shell variable var.
> > +# var should be the name of a shell variable.
> > +# Its value should not contain a newline and not start or end with 
> > whitespace.
> > +# prefix should not contain the characters "$`\{}|.
> 
> Not sure whether this comment is meant to list the dot as one of the
> forbidden characters, but neither prefix nor suffix should contain a
> dot in the general case, because the sed script will match any
> character at that position.

Good catch. You're right. If the prefix or suffix contains a dot, it needs
to be escaped.

> Of course, your documentation should also list the characters
>   [ ] ^
> as forbidden (both prefix and suffix).  Likewise for
> func_filter_filelist.

You're right again. Done as follows:


2009-01-17  Bruno Haible  <address@hidden>

        * gnulib-tool (func_remove_prefix): Escape all dots in the prefix.
        Update documentation.
        (func_remove_suffix): Escape all dots in the suffix. Update
        documentation.
        (func_filter_filelist): Update documentation.
        Reported by Ralf Wildenhues.

--- gnulib-tool.orig    2009-01-18 04:07:14.000000000 +0100
+++ gnulib-tool 2009-01-18 04:07:08.000000000 +0100
@@ -411,7 +411,7 @@
 # removes the given prefix from the value of the shell variable var.
 # var should be the name of a shell variable.
 # Its value should not contain a newline and not start or end with whitespace.
-# prefix should not contain the characters "$`\{}|.
+# prefix should not contain the characters "$`\{}[]^|.
 if ( foo=bar; eval 'test "${foo#b}" = ar' ) >/dev/null 2>&1; then
   func_remove_prefix ()
   {
@@ -423,6 +423,12 @@
   {
     eval "value=\"\$$1\""
     prefix="$2"
+    case "$prefix" in
+      *.*)
+        sed_escape_dots='s/\([.]\)/\\\1/g'
+        prefix=`echo "$prefix" | sed -e "$sed_escape_dots"`
+        ;;
+    esac
     value=`echo "$value" | sed -e "s|^${prefix}||"`
     eval "$1=\"\$value\""
   }
@@ -433,7 +439,7 @@
 # removes the given suffix from the value of the shell variable var.
 # var should be the name of a shell variable.
 # Its value should not contain a newline and not start or end with whitespace.
-# suffix should not contain the characters "$`\{}|.
+# suffix should not contain the characters "$`\{}[]^|.
 if ( foo=bar; eval 'test "${foo%r}" = ba' ) >/dev/null 2>&1; then
   func_remove_suffix ()
   {
@@ -445,6 +451,12 @@
   {
     eval "value=\"\$$1\""
     suffix="$2"
+    case "$suffix" in
+      *.*)
+        sed_escape_dots='s/\([.]\)/\\\1/g'
+        suffix=`echo "$suffix" | sed -e "$sed_escape_dots"`
+        ;;
+    esac
     value=`echo "$value" | sed -e "s|${suffix}\$||"`
     eval "$1=\"\$value\""
   }
@@ -1379,7 +1391,7 @@
 # elements starting with prefix and ending with suffix are considered.
 # Processing: removed_prefix and removed_suffix are removed from each element,
 # added_prefix and added_suffix are added to each element.
-# removed_prefix, removed_suffix should not contain the characters "$`\{}|.
+# removed_prefix, removed_suffix should not contain the characters "$`\{}[]^|.
 # added_prefix, added_suffix should not contain the characters \|.
 func_filter_filelist ()
 {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]