pkgsrc-Changes archive

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

CVS commit: pkgsrc



Module Name:    pkgsrc
Committed By:   rillig
Date:           Wed May 22 20:47:05 UTC 2019

Modified Files:
        pkgsrc/mk/tools: shquote.sh
        pkgsrc/regress/tools/files: logging-test.sh shquote-test.sh

Log Message:
mk/tools: in the wrapper log, quote arguments containing = naturally


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 pkgsrc/mk/tools/shquote.sh
cvs rdiff -u -r1.6 -r1.7 pkgsrc/regress/tools/files/logging-test.sh
cvs rdiff -u -r1.1 -r1.2 pkgsrc/regress/tools/files/shquote-test.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/mk/tools/shquote.sh
diff -u pkgsrc/mk/tools/shquote.sh:1.1 pkgsrc/mk/tools/shquote.sh:1.2
--- pkgsrc/mk/tools/shquote.sh:1.1      Sun Mar 24 11:29:19 2019
+++ pkgsrc/mk/tools/shquote.sh  Wed May 22 20:47:05 2019
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: shquote.sh,v 1.1 2019/03/24 11:29:19 rillig Exp $
+# $NetBSD: shquote.sh,v 1.2 2019/05/22 20:47:05 rillig Exp $
 
 # Quotes all shell meta characters from $1 and writes the result to $shquoted.
 shquote()
@@ -7,13 +7,27 @@ shquote()
        shquoted=$1
        case $shquoted in
        *\'*)
-               shquoted=`$tools_wrapper_sed -e 's,'\'','\''\\\\'\'''\'',g' <<EOF
+               # replace each ' with '\''
+               shquoted=`$tools_wrapper_sed -e "s,','\\\\\\\\'',g" <<EOF
 $shquoted
 EOF`
        esac
 
        case $shquoted in
-       *[!!%+,\-./0-9:=@A-Z_a-z]*|'')
+       (*[!!%+,\-./0-9:=@A-Z_a-z]*|'')
+
+               # Move the single quote after the first equals sign, so that
+               # macro definitions look like -DMACRO='"value"' instead of
+               # the less common '-DMACRO="value"'.
+               case $shquoted in
+               (*=*)   lhs=${shquoted%%=*}
+                       case $lhs in
+                       (*[!!%+,\-./0-9:=@A-Z_a-z]*|'') ;;
+                       (*)     shquoted="$lhs='${shquoted#*=}'"
+                               return
+                       esac
+               esac
+
                shquoted="'$shquoted'"
        esac
 }

Index: pkgsrc/regress/tools/files/logging-test.sh
diff -u pkgsrc/regress/tools/files/logging-test.sh:1.6 pkgsrc/regress/tools/files/logging-test.sh:1.7
--- pkgsrc/regress/tools/files/logging-test.sh:1.6      Sun Mar 24 11:29:19 2019
+++ pkgsrc/regress/tools/files/logging-test.sh  Wed May 22 20:47:05 2019
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: logging-test.sh,v 1.6 2019/03/24 11:29:19 rillig Exp $
+# $NetBSD: logging-test.sh,v 1.7 2019/05/22 20:47:05 rillig Exp $
 
 # Up to March 2019, the command logging for the wrapped tools didn't properly
 # quote the command line arguments. This meant the logging did not reflect
@@ -152,7 +152,7 @@ test_case "TOOLS_SCRIPT with actual argu
                -DB=\"a\ b\"
 
        assert_log <<'EOF'
-[*] WRKDIR/.tools/bin/for-loop '-DSD="a b"' '-DSS='\''a b'\''' '-DDD="a b"' '-DB="a b"'
-<.> set args '-DSD="a b"' '-DSS='\''a b'\''' '-DDD="a b"' '-DB="a b"'; shift; printf '%s' "$0";  for arg in "$@"; do  printf ' <%s>' "$arg";  done;  printf '\n'
+[*] WRKDIR/.tools/bin/for-loop -DSD='"a b"' -DSS=''\''a b'\''' -DDD='"a b"' -DB='"a b"'
+<.> set args -DSD='"a b"' -DSS=''\''a b'\''' -DDD='"a b"' -DB='"a b"'; shift; printf '%s' "$0";  for arg in "$@"; do  printf ' <%s>' "$arg";  done;  printf '\n'
 EOF
 }

Index: pkgsrc/regress/tools/files/shquote-test.sh
diff -u pkgsrc/regress/tools/files/shquote-test.sh:1.1 pkgsrc/regress/tools/files/shquote-test.sh:1.2
--- pkgsrc/regress/tools/files/shquote-test.sh:1.1      Sun Mar 24 11:29:19 2019
+++ pkgsrc/regress/tools/files/shquote-test.sh  Wed May 22 20:47:05 2019
@@ -52,3 +52,12 @@ test_shquote '-e asdf' becomes "'-e asdf
 test_shquote '-n' becomes '-n'
 test_shquote '\\\\\\\\' becomes \''\\\\\\\\'\'
 test_shquote \"\$\'\;\<\\\` becomes \'\"\$\'\\\'\'\;\<\\\`\'
+
+# Move the single quote to the right of the equals sign, if possible.
+test_shquote '-DMACRO="value"' becomes "-DMACRO='\"value\"'"
+test_shquote '--prefix="/usr/local"' becomes "--prefix='\"/usr/local\"'"
+test_shquote '-assignment=first=second=""' becomes "-assignment='first=second=\"\"'"
+test_shquote '-assignment=first=second' becomes '-assignment=first=second'
+
+# If the left-hand side needs to be quoted as well, quote the whole string.
+test_shquote '"left"="right"' becomes "'\"left\"=\"right\"'"



Home | Main Index | Thread Index | Old Index