-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
flag: Parse incorrectly interprets quoted path with a trailing slash as having escaped quotes. #16131
Comments
@jterry75 FYI |
Is there a document somewhere that explains how Windows treats quotes on the command line? I'd like to understand it once and for all. |
Most Windows programs call CommandLineToArgvW WinAPI (or similar) to parse input parameters. Go does too. Go also has syscall.EscapeArg to do the opposite - convert []string into command line string. The syscall.EscapeArg doc also has some references. Some Windows programs use different rules for encoding []string into command line. Most notably cmd.exe and msiexec.exe (see #15566 for details). Alex |
This is working as expected. Go does not have its own command line into parameter list converter (not yet). It uses Windows CommandLineToArgvW for that job. And CommandLineToArgvW converts
into
See https://msdn.microsoft.com/en-us/library/ms880421 for CommandLineToArgvW rules. Luckily we also have new CL https://go-review.googlesource.com/#/c/22932 pending, that replaces call into Windows CommandLineToArgvW with a Go code. I just tried adding your command line to the test there https://go-review.googlesource.com/#/c/22932/2/src/os/exec_windows_test.go@32, and the test still pass. I also printed
As you can see, the last line looks just like output of your program. Alex |
Please answer these questions before submitting your issue. Thanks!
go version
)?go version go1.6.2 windows/amd64
go env
)?set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=s:\docker
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=1
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
using import "flag" and Windows cmd, compile this program into an executable:
import (
"flag"
"fmt"
)
func main() {
flag.Parse()
fmt.Println(flag.Arg(0))
}
and then run it using the following argument:
test.exe "c:\test\"
Either the argument as passed at the cmdline,
"c:\test\"
, or the argument with the quotes stripped,c:\test\
.The program displays
c:\test\"
because somehowflag.Parse()
incorrectly interprets the seconds quote as being escaped.The text was updated successfully, but these errors were encountered: