summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorapb <apb@NetBSD.org>2014-08-04 21:56:30 +0000
committerapb <apb@NetBSD.org>2014-08-04 21:56:30 +0000
commit2dd73bdfb8ffc2ffd45bb75e3c938dccc6c929bf (patch)
treee9bf566aa6b419341393afd8ccc75d717b053f35
parent465b0d3ef8dc52768488795fd0adec19fb7280a7 (diff)
Synchronise several shell_quote implementations, and:
* Elide some unnecessary pairs of quotation marks, to improve readability. For example, shell_quote "''" is now \'\' instead of ''\'''\'''. * Don't add quotes around words that contain only safe characters, to improve readability. * LC_COLLATE=C to prevent [a-zA-Z] from matching non-ASCII characters. * Use ${SED} if defined.
-rwxr-xr-xbuild.sh46
-rw-r--r--share/zoneinfo/tzdata2netbsd26
-rw-r--r--usr.bin/locate/locate/updatedb.sh43
-rw-r--r--usr.sbin/etcupdate/etcupdate44
-rwxr-xr-xusr.sbin/postinstall/postinstall44
5 files changed, 152 insertions, 51 deletions
diff --git a/build.sh b/build.sh
index 893598e54ef..42bba077faf 100755
--- a/build.sh
+++ b/build.sh
@@ -1,5 +1,5 @@
#! /usr/bin/env sh
-# $NetBSD: build.sh,v 1.288 2014/08/03 17:11:44 riz Exp $
+# $NetBSD: build.sh,v 1.289 2014/08/04 21:56:30 apb Exp $
#
# Copyright (c) 2001-2011 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -286,21 +286,43 @@ ERRORMESSAGE
# eval "set -- $quotedlist"
# or like this:
# eval "\$command $quotedlist \$filename"
+#
shell_quote()
-{
+{(
local result=''
- local arg
+ local arg qarg
+ LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
for arg in "$@" ; do
- # Append a space if necessary
- result="${result}${result:+ }"
- # Convert each embedded ' to '\'',
- # then insert ' at the beginning of the first line,
- # and append ' at the end of the last line.
- result="${result}$(printf "%s\n" "$arg" | \
- sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
+ case "${arg}" in
+ '')
+ qarg="''"
+ ;;
+ *[!-./a-zA-Z0-9]*)
+ # Convert each embedded ' to '\'',
+ # then insert ' at the beginning of the first line,
+ # and append ' at the end of the last line.
+ # Finally, elide unnecessary '' pairs at the
+ # beginning and end of the result and as part of
+ # '\'''\'' sequences that result from multiple
+ # adjacent quotes in he input.
+ qarg="$(printf "%s\n" "$arg" | \
+ ${SED:-sed} -e "s/'/'\\\\''/g" \
+ -e "1s/^/'/" -e "\$s/\$/'/" \
+ -e "1s/^''//" -e "\$s/''\$//" \
+ -e "s/'''/'/g"
+ )"
+ ;;
+ *)
+ # Arg is not the empty string, and does not contain
+ # any unsafe characters. Leave it unchanged for
+ # readability.
+ qarg="${arg}"
+ ;;
+ esac
+ result="${result}${result:+ }${qarg}"
done
printf "%s\n" "$result"
-}
+)}
statusmsg()
{
@@ -1774,7 +1796,7 @@ createmakewrapper()
eval cat <<EOF ${makewrapout}
#! ${HOST_SH}
# Set proper variables to allow easy "make" building of a NetBSD subtree.
-# Generated from: \$NetBSD: build.sh,v 1.288 2014/08/03 17:11:44 riz Exp $
+# Generated from: \$NetBSD: build.sh,v 1.289 2014/08/04 21:56:30 apb Exp $
# with these arguments: ${_args}
#
diff --git a/share/zoneinfo/tzdata2netbsd b/share/zoneinfo/tzdata2netbsd
index 4ab7df5dc59..85bd65dfc4c 100644
--- a/share/zoneinfo/tzdata2netbsd
+++ b/share/zoneinfo/tzdata2netbsd
@@ -1,4 +1,4 @@
-# $NetBSD: tzdata2netbsd,v 1.3 2014/06/13 19:56:19 apb Exp $
+# $NetBSD: tzdata2netbsd,v 1.4 2014/08/04 21:56:30 apb Exp $
# For use by NetBSD developers when updating to new versions of tzdata.
#
@@ -75,29 +75,43 @@ DOIT()
# eval "set -- $quotedlist"
# or like this:
# eval "\$command $quotedlist \$filename"
+#
shell_quote()
-{
+{(
local result=''
local arg qarg
+ LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
for arg in "$@" ; do
case "${arg}" in
- ''|*[!-./a-zA-Z0-9]*)
+ '')
+ qarg="''"
+ ;;
+ *[!-./a-zA-Z0-9]*)
# Convert each embedded ' to '\'',
# then insert ' at the beginning of the first line,
# and append ' at the end of the last line.
+ # Finally, elide unnecessary '' pairs at the
+ # beginning and end of the result and as part of
+ # '\'''\'' sequences that result from multiple
+ # adjacent quotes in he input.
qarg="$(printf "%s\n" "$arg" | \
- sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
+ ${SED:-sed} -e "s/'/'\\\\''/g" \
+ -e "1s/^/'/" -e "\$s/\$/'/" \
+ -e "1s/^''//" -e "\$s/''\$//" \
+ -e "s/'''/'/g"
+ )"
;;
*)
# Arg is not the empty string, and does not contain
- # any unsafe characters.
+ # any unsafe characters. Leave it unchanged for
+ # readability.
qarg="${arg}"
;;
esac
result="${result}${result:+ }${qarg}"
done
printf "%s\n" "$result"
-}
+)}
findcvsroot()
{
diff --git a/usr.bin/locate/locate/updatedb.sh b/usr.bin/locate/locate/updatedb.sh
index ce52f61851e..1a72f74bcd2 100644
--- a/usr.bin/locate/locate/updatedb.sh
+++ b/usr.bin/locate/locate/updatedb.sh
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $NetBSD: updatedb.sh,v 1.14 2011/07/13 07:58:35 apb Exp $
+# $NetBSD: updatedb.sh,v 1.15 2014/08/04 21:56:30 apb Exp $
#
# Copyright (c) 1989, 1993
# The Regents of the University of California. All rights reserved.
@@ -61,20 +61,41 @@ SRCHPATHS=
# eval "\$command $quotedlist \$filename"
#
shell_quote()
-{
+{(
local result=''
- local arg
+ local arg qarg
+ LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
for arg in "$@" ; do
- # Append a space if necessary
- result="${result}${result:+ }"
- # Convert each embedded ' to '\'',
- # then insert ' at the beginning of the first line,
- # and append ' at the end of the last line.
- result="${result}$(printf "%s\n" "$arg" | \
- sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
+ case "${arg}" in
+ '')
+ qarg="''"
+ ;;
+ *[!-./a-zA-Z0-9]*)
+ # Convert each embedded ' to '\'',
+ # then insert ' at the beginning of the first line,
+ # and append ' at the end of the last line.
+ # Finally, elide unnecessary '' pairs at the
+ # beginning and end of the result and as part of
+ # '\'''\'' sequences that result from multiple
+ # adjacent quotes in he input.
+ qarg="$(printf "%s\n" "$arg" | \
+ ${SED:-sed} -e "s/'/'\\\\''/g" \
+ -e "1s/^/'/" -e "\$s/\$/'/" \
+ -e "1s/^''//" -e "\$s/''\$//" \
+ -e "s/'''/'/g"
+ )"
+ ;;
+ *)
+ # Arg is not the empty string, and does not contain
+ # any unsafe characters. Leave it unchanged for
+ # readability.
+ qarg="${arg}"
+ ;;
+ esac
+ result="${result}${result:+ }${qarg}"
done
printf "%s\n" "$result"
-}
+)}
# read configuration file
if [ -f "$CONF" ]; then
diff --git a/usr.sbin/etcupdate/etcupdate b/usr.sbin/etcupdate/etcupdate
index 1466afa4ba5..88952118dba 100644
--- a/usr.sbin/etcupdate/etcupdate
+++ b/usr.sbin/etcupdate/etcupdate
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $NetBSD: etcupdate,v 1.57 2014/06/16 22:12:30 apb Exp $
+# $NetBSD: etcupdate,v 1.58 2014/08/04 21:56:30 apb Exp $
#
# Copyright (c) 2001-2008 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -138,21 +138,43 @@ yesno() {
# eval "set -- $quotedlist"
# or like this:
# eval "\$command $quotedlist \$filename"
+#
shell_quote()
-{
+{(
local result=''
- local arg
+ local arg qarg
+ LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
for arg in "$@" ; do
- # Append a space if necessary
- result="${result}${result:+ }"
- # Convert each embedded ' to '\'',
- # then insert ' at the beginning of the first line,
- # and append ' at the end of the last line.
- result="${result}$(printf "%s\n" "$arg" | \
- sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
+ case "${arg}" in
+ '')
+ qarg="''"
+ ;;
+ *[!-./a-zA-Z0-9]*)
+ # Convert each embedded ' to '\'',
+ # then insert ' at the beginning of the first line,
+ # and append ' at the end of the last line.
+ # Finally, elide unnecessary '' pairs at the
+ # beginning and end of the result and as part of
+ # '\'''\'' sequences that result from multiple
+ # adjacent quotes in he input.
+ qarg="$(printf "%s\n" "$arg" | \
+ ${SED:-sed} -e "s/'/'\\\\''/g" \
+ -e "1s/^/'/" -e "\$s/\$/'/" \
+ -e "1s/^''//" -e "\$s/''\$//" \
+ -e "s/'''/'/g"
+ )"
+ ;;
+ *)
+ # Arg is not the empty string, and does not contain
+ # any unsafe characters. Leave it unchanged for
+ # readability.
+ qarg="${arg}"
+ ;;
+ esac
+ result="${result}${result:+ }${qarg}"
done
printf "%s\n" "$result"
-}
+)}
# Convert arg $1 to a basic regular expression (as in sed)
# that will match the arg. This works by inserting backslashes
diff --git a/usr.sbin/postinstall/postinstall b/usr.sbin/postinstall/postinstall
index 88f9e2ecaec..95327b3b250 100755
--- a/usr.sbin/postinstall/postinstall
+++ b/usr.sbin/postinstall/postinstall
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $NetBSD: postinstall,v 1.174 2014/06/16 22:12:30 apb Exp $
+# $NetBSD: postinstall,v 1.175 2014/08/04 21:56:30 apb Exp $
#
# Copyright (c) 2002-2008 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -112,21 +112,43 @@ mkdtemp()
# eval "set -- $quotedlist"
# or like this:
# eval "\$command $quotedlist \$filename"
+#
shell_quote()
-{
+{(
local result=''
- local arg
+ local arg qarg
+ LC_COLLATE=C ; export LC_COLLATE # so [a-zA-Z0-9] works in ASCII
for arg in "$@" ; do
- # Append a space if necessary
- result="${result}${result:+ }"
- # Convert each embedded ' to '\'',
- # then insert ' at the beginning of the first line,
- # and append ' at the end of the last line.
- result="${result}$(printf "%s\n" "$arg" | \
- ${SED} -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/")"
+ case "${arg}" in
+ '')
+ qarg="''"
+ ;;
+ *[!-./a-zA-Z0-9]*)
+ # Convert each embedded ' to '\'',
+ # then insert ' at the beginning of the first line,
+ # and append ' at the end of the last line.
+ # Finally, elide unnecessary '' pairs at the
+ # beginning and end of the result and as part of
+ # '\'''\'' sequences that result from multiple
+ # adjacent quotes in he input.
+ qarg="$(printf "%s\n" "$arg" | \
+ ${SED:-sed} -e "s/'/'\\\\''/g" \
+ -e "1s/^/'/" -e "\$s/\$/'/" \
+ -e "1s/^''//" -e "\$s/''\$//" \
+ -e "s/'''/'/g"
+ )"
+ ;;
+ *)
+ # Arg is not the empty string, and does not contain
+ # any unsafe characters. Leave it unchanged for
+ # readability.
+ qarg="${arg}"
+ ;;
+ esac
+ result="${result}${result:+ }${qarg}"
done
printf "%s\n" "$result"
-}
+)}
# Convert arg $1 to a basic regular expression (as in sed)
# that will match the arg. This works by inserting backslashes