From 6d88b01d1e2bb2a76d4e0f094f1e895e3b16c859 Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 30 Aug 2018 11:08:51 +0000 Subject: test-cases to cover quoting of the newline character, and the documentation extended. --- doc/exec.n | 17 +++++++++++++++++ tests/winPipe.test | 30 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/doc/exec.n b/doc/exec.n index 3857a71..e40b596 100644 --- a/doc/exec.n +++ b/doc/exec.n @@ -207,6 +207,19 @@ information is instead sent to the console, if one is present, or is discarded. .RS .PP +Note that the current escape resp. quoting of arguments for windows works only +with executables using CommandLineToArgv, CRT-library or similar, as well as +with the windows batch files (excepting the newline, see below). +Although it is the common escape algorithm, but, in fact, the way how the +executable parses the command-line (resp. splits it into single arguments) +is decisive. +.PP +Unfortunately, there is currently no way to supply newline character within +an argument to the batch files (\fB.cmd\fR or \fB.bat\fR) or to the command +processor (\fBcmd.exe /c\fR), because this causes truncation of command-line +(also the argument chain) on the first newline character. +But it works properly with an executable (using CommandLineToArgv, etc). +.PP The Tk console text widget does not provide real standard IO capabilities. Under Tk, when redirecting from standard input, all applications will see an immediate end-of-file; information redirected to standard output or standard @@ -415,6 +428,10 @@ that sometimes pop up: .CE With the file \fIcmp.bat\fR looking something like: .CS +@gcc %* +.CE +or like another variant using single parameters: +.CS @gcc %1 %2 %3 %4 %5 %6 %7 %8 %9 .CE .PP diff --git a/tests/winPipe.test b/tests/winPipe.test index 4385690..6a02147 100644 --- a/tests/winPipe.test +++ b/tests/winPipe.test @@ -348,6 +348,10 @@ proc _testExecArgs {single args} { if {$r ne $e} { append broken "\[ERROR\]: exec [file extension [lindex $cmd 0]] on $args\n -- result:\n$r\n -- expected:\n$e\n" } + if {$single & 8} { + # if test exe only: + break + } } } return $broken @@ -555,6 +559,32 @@ test winpipe-8.5 {BuildCommandLine/parse_cmdline pass-thru: check injection on s unset -nocomplain lst args a map maps } +set injectList { + "test\"\nwhoami" "test\"\"\nwhoami" + "test\"\"\"\nwhoami" "test\"\"\"\"\nwhoami" + "test;\n&echo \"" "\"test;\n&echo \"" + "test\";\n&echo \"" "\"test\";\n&echo \"" + "\"\"test\";\n&echo \"" +} + +test winpipe-8.6 {BuildCommandLine/parse_cmdline pass-thru: check new-line quoted in args} \ +-constraints {win exec} -body { + # test exe only, because currently there is no proper way to escape a new-line char resp. + # to supply a new-line to the batch-files within arguments (command line is truncated). + _testExecArgs 8 \ + [list START {*}$injectList END] \ + [list "START\"" {*}$injectList END] \ + [list START {*}$injectList "\"END"] \ + [list "START\"" {*}$injectList "\"END"] +} -result {} + +test winpipe-8.7 {BuildCommandLine/parse_cmdline pass-thru: check new-line quoted in args (batch)} \ +-constraints {win exec knownBug} -body { + # this will fail if executed batch-file, because currently there is no proper way to escape a new-line char. + _testExecArgs 0 $injectList +} -result {} + + rename _testExecArgs {} # restore old values for env(TMP) and env(TEMP) -- cgit v0.12