From 8beba3caf9e38c7755dc9d3d4bc6d2d795d75aa5 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Thu, 22 Dec 2011 03:46:41 -0500 Subject: [PATCH] Avoid bash regexps Turns out that bash's regexps (using `=~') changed so that quoting them matches a literal string, and it seems dangerous to rely on parsing unquoted regexps. One way around this is to put the regexp in a variable, but for the two simple uses that this script had, it's easy to avoid regexps completely. --- collects/meta/build/build | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/collects/meta/build/build b/collects/meta/build/build index d743474c6b..f72f7d3953 100755 --- a/collects/meta/build/build +++ b/collects/meta/build/build @@ -116,6 +116,8 @@ msets "/" ulimit -c unlimited # make sure that everything is group-readable umask 002 +# needed for some hacks below +shopt -s extglob # get this script's name and path cd "$(dirname "$0")" @@ -382,7 +384,6 @@ cleanup_lockfile() { # associative arrays, with names that are treated similarly to paths and a # default context similar to the current directory. (Implemented as plain # variables, using "__" as the translation of "/" level separators.) -shopt -s extglob # needed for some hacks below mcontext="/" # the current context for m-ops mset() { # mset goes over all args, which can have the following shapes: @@ -497,9 +498,9 @@ is_yes() { while true; do echo_n ">>> QUESTION >>> $var [y/n/Y/N] ? " 1>&2 if [[ "$fixed_reply" != "" ]]; then reply="$fixed_reply" - elif [[ "$ask_answers" =~ "^(.)(.*)$" ]]; then - reply="${BASH_REMATCH[1]}" - ask_answers="${BASH_REMATCH[2]}" + elif [[ "x$ask_answers" != "x" ]]; then + reply="${ask_answers:0:1}" + ask_answers="${ask_answers:1}" else read -sn 1 reply; fi echo "$reply" 1>&2 case "$reply" in @@ -995,7 +996,7 @@ MAIN_BUILD() { htmltimestamp="$(date '+updated at %A, %B %d %Y, %H:%M %Z')" if [[ "$1" = "ask" ]]; then ask_mode="yes"; shift - if [[ "$1" =~ "[yYnN ][yYnN ]*" ]]; then + if [[ "$1" = +([yYnN ]) ]]; then ask_answers="$(echo "$1" | tr -d ' ')"; shift fi fi