From 8858a0f2c933c07a3c497ac705e2e06463a04ff3 Mon Sep 17 00:00:00 2001 From: davygrvy Date: Wed, 25 Feb 2004 07:56:11 +0000 Subject: backport of BuildCommandLine changes to mirror msvcrt's parse_cmdline() rules of quoting --- tests/winPipe.test | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++--- win/tclWinPipe.c | 26 +++++------- 2 files changed, 125 insertions(+), 21 deletions(-) diff --git a/tests/winPipe.test b/tests/winPipe.test index 26a7e33..60e7dd5 100644 --- a/tests/winPipe.test +++ b/tests/winPipe.test @@ -12,7 +12,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: winPipe.test,v 1.22 2002/12/17 02:47:39 davygrvy Exp $ +# RCS: @(#) $Id: winPipe.test,v 1.22.2.1 2004/02/25 07:56:11 davygrvy Exp $ package require tcltest namespace import -force ::tcltest::* @@ -315,12 +315,122 @@ set path(echoArgs.tcl) [makeFile { puts "[list $argv0 $argv]" } echoArgs.tcl] +### validate the raw output of BuildCommandLine(). +### test winpipe-7.1 {BuildCommandLine: null arguments} {pcOnly exec} { - exec [interpreter] $path(echoArgs.tcl) foo "" bar -} [list $path(echoArgs.tcl) {foo {} bar}] + exec $env(COMSPEC) /c echo foo "" bar +} {foo "" bar} test winpipe-7.2 {BuildCommandLine: null arguments} {pcOnly exec} { - exec [interpreter] $path(echoArgs.tcl) foo \" bar -} [list $path(echoArgs.tcl) {foo {"} bar}] + exec $env(COMSPEC) /c echo foo {} bar +} {foo "" bar} +test winpipe-7.3 {BuildCommandLine: dbl quote quoting #1} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo {"} bar +} {foo \" bar} +test winpipe-7.4 {BuildCommandLine: dbl quote quoting #2} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo {""} bar +} {foo \"\" bar} +test winpipe-7.5 {BuildCommandLine: dbl quote quoting #3} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo {" } bar +} {foo "\" " bar} +test winpipe-7.6 {BuildCommandLine: dbl quote quoting #4} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo {a="b"} bar +} {foo a=\"b\" bar} +test winpipe-7.7 {BuildCommandLine: dbl quote quoting #5} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo {a = "b"} bar +} {foo "a = \"b\"" bar} +test winpipe-7.8 {BuildCommandLine: dbl quote quoting #6} {pcOnly exec} { + exec $env(COMSPEC) /c echo {"hello"} {""hello""} {"""hello"""} {"\"hello\""} {he llo} {he " llo} +} {\"hello\" \"\"hello\"\" \"\"\"hello\"\"\" \"\\\"hello\\\"\" "he llo" "he \" llo"} +test winpipe-7.9 {BuildCommandLine: N backslashes followed a quote rule #1} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo \\ bar +} {foo \ bar} +test winpipe-7.10 {BuildCommandLine: N backslashes followed a quote rule #2} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo \\\\ bar +} {foo \\ bar} +test winpipe-7.11 {BuildCommandLine: N backslashes followed a quote rule #3} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo \\\ \\ bar +} {foo "\ \\" bar} +test winpipe-7.12 {BuildCommandLine: N backslashes followed a quote rule #4} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo \\\ \\\\ bar +} {foo "\ \\\\" bar} +test winpipe-7.13 {BuildCommandLine: N backslashes followed a quote rule #5} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo \\\ \\\\\\ bar +} {foo "\ \\\\\\" bar} +test winpipe-7.14 {BuildCommandLine: N backslashes followed a quote rule #6} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo \\\ \\\" bar +} {foo "\ \\\"" bar} +test winpipe-7.15 {BuildCommandLine: N backslashes followed a quote rule #7} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo \\\ \\\\\" bar +} {foo "\ \\\\\"" bar} +test winpipe-7.16 {BuildCommandLine: N backslashes followed a quote rule #8} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo \\\ \\\\\\\" bar +} {foo "\ \\\\\\\"" bar} +test winpipe-7.17 {BuildCommandLine: special chars #4} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo \{ bar +} "foo \{ bar" +test winpipe-7.18 {BuildCommandLine: special chars #5} {pcOnly exec} { + exec $env(COMSPEC) /c echo foo \} bar +} "foo \} bar" + +### validate the pass-thru from BuildCommandLine() to the crt's parse_cmdline(). +### +test winpipe-8.1 {BuildCommandLine/parse_cmdline pass-thru: null arguments} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo "" bar +} [list $path(echoArgs.tcl) [list foo {} bar]] +test winpipe-8.2 {BuildCommandLine/parse_cmdline pass-thru: null arguments} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo {} bar +} [list $path(echoArgs.tcl) [list foo {} bar]] +test winpipe-8.3 {BuildCommandLine/parse_cmdline pass-thru: dbl quote quoting #1} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo {"} bar +} [list $path(echoArgs.tcl) [list foo {"} bar]] +test winpipe-8.4 {BuildCommandLine/parse_cmdline pass-thru: dbl quote quoting #2} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo {""} bar +} [list $path(echoArgs.tcl) [list foo {""} bar]] +test winpipe-8.5 {BuildCommandLine/parse_cmdline pass-thru: dbl quote quoting #3} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo {" } bar +} [list $path(echoArgs.tcl) [list foo {" } bar]] +test winpipe-8.6 {BuildCommandLine/parse_cmdline pass-thru: dbl quote quoting #4} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo {a="b"} bar +} [list $path(echoArgs.tcl) [list foo {a="b"} bar]] +test winpipe-8.7 {BuildCommandLine/parse_cmdline pass-thru: dbl quote quoting #5} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo {a = "b"} bar +} [list $path(echoArgs.tcl) [list foo {a = "b"} bar]] +test winpipe-8.8 {BuildCommandLine/parse_cmdline pass-thru: dbl quote quoting #6} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) {"hello"} {""hello""} {"""hello"""} {"\"hello\""} {he llo} {he " llo} +} [list $path(echoArgs.tcl) [list {"hello"} {""hello""} {"""hello"""} {"\"hello\""} {he llo} {he " llo}]] +test winpipe-8.9 {BuildCommandLine/parse_cmdline pass-thru: N backslashes followed a quote rule #1} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo \\ bar +} [list $path(echoArgs.tcl) [list foo \\ bar]] +test winpipe-8.10 {BuildCommandLine/parse_cmdline pass-thru: N backslashes followed a quote rule #2} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo \\\\ bar +} [list $path(echoArgs.tcl) [list foo \\\\ bar]] +test winpipe-8.11 {BuildCommandLine/parse_cmdline pass-thru: N backslashes followed a quote rule #3} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo \\\ \\ bar +} [list $path(echoArgs.tcl) [list foo \\\ \\ bar]] +test winpipe-8.12 {BuildCommandLine/parse_cmdline pass-thru: N backslashes followed a quote rule #4} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo \\\ \\\\ bar +} [list $path(echoArgs.tcl) [list foo \\\ \\\\ bar]] +test winpipe-8.13 {BuildCommandLine/parse_cmdline pass-thru: N backslashes followed a quote rule #5} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo \\\ \\\\\\ bar +} [list $path(echoArgs.tcl) [list foo \\\ \\\\\\ bar]] +test winpipe-8.14 {BuildCommandLine/parse_cmdline pass-thru: N backslashes followed a quote rule #6} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo \\\ \\\" bar +} [list $path(echoArgs.tcl) [list foo \\\ \\\" bar]] +test winpipe-8.15 {BuildCommandLine/parse_cmdline pass-thru: N backslashes followed a quote rule #7} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo \\\ \\\\\" bar +} [list $path(echoArgs.tcl) [list foo \\\ \\\\\" bar]] +test winpipe-8.16 {BuildCommandLine/parse_cmdline pass-thru: N backslashes followed a quote rule #8} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo \\\ \\\\\\\" bar +} [list $path(echoArgs.tcl) [list foo \\\ \\\\\\\" bar]] +test winpipe-8.17 {BuildCommandLine/parse_cmdline pass-thru: special chars #1} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo \{ bar +} [list $path(echoArgs.tcl) [list foo \{ bar]] +test winpipe-8.18 {BuildCommandLine/parse_cmdline pass-thru: special chars #2} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo \} bar +} [list $path(echoArgs.tcl) [list foo \} bar]] +test winpipe-8.19 {ensure parse_cmdline isn't doing wildcard replacement} {pcOnly exec} { + exec [interpreter] $path(echoArgs.tcl) foo * makefile.?c bar +} [list $path(echoArgs.tcl) [list foo * makefile.?c bar]] # restore old values for env(TMP) and env(TEMP) diff --git a/win/tclWinPipe.c b/win/tclWinPipe.c index 320f99e..ffc6429 100644 --- a/win/tclWinPipe.c +++ b/win/tclWinPipe.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinPipe.c,v 1.33.2.5 2003/10/21 22:57:18 andreas_kupries Exp $ + * RCS: @(#) $Id: tclWinPipe.c,v 1.33.2.6 2004/02/25 07:56:21 davygrvy Exp $ */ #include "tclWinInt.h" @@ -1577,10 +1577,9 @@ BuildCommandLine( arg = executable; } else { arg = argv[i]; + Tcl_DStringAppend(&ds, " ", 1); } - if(Tcl_DStringLength(&ds) > 0) Tcl_DStringAppend(&ds, " ", 1); - quote = 0; if (arg[0] == '\0') { quote = 1; @@ -1598,47 +1597,42 @@ BuildCommandLine( if (quote) { Tcl_DStringAppend(&ds, "\"", 1); } - start = arg; for (special = arg; ; ) { if ((*special == '\\') && - (special[1] == '\\' || special[1] == '"')) { - Tcl_DStringAppend(&ds, start, special - start); + (special[1] == '\\' || special[1] == '"' || (quote && special[1] == '\0'))) { + Tcl_DStringAppend(&ds, start, (int) (special - start)); start = special; while (1) { special++; - if (*special == '"') { + if (*special == '"' || (quote && *special == '\0')) { /* * N backslashes followed a quote -> insert * N * 2 + 1 backslashes then a quote. */ - Tcl_DStringAppend(&ds, start, special - start); + Tcl_DStringAppend(&ds, start, + (int) (special - start)); break; } if (*special != '\\') { break; } } - Tcl_DStringAppend(&ds, start, special - start); + Tcl_DStringAppend(&ds, start, (int) (special - start)); start = special; } if (*special == '"') { - Tcl_DStringAppend(&ds, start, special - start); + Tcl_DStringAppend(&ds, start, (int) (special - start)); Tcl_DStringAppend(&ds, "\\\"", 2); start = special + 1; } - if (*special == '{') { - Tcl_DStringAppend(&ds, start, special - start); - Tcl_DStringAppend(&ds, "\\{", 2); - start = special + 1; - } if (*special == '\0') { break; } special++; } - Tcl_DStringAppend(&ds, start, special - start); + Tcl_DStringAppend(&ds, start, (int) (special - start)); if (quote) { Tcl_DStringAppend(&ds, "\"", 1); } -- cgit v0.12