go-shellwords icon indicating copy to clipboard operation
go-shellwords copied to clipboard

bug: Parse function removes needed backslashes

Open jftuga opened this issue 6 years ago • 8 comments

In Windows, backslashes are used at the OS path separator. When I run this code, I get an incorrect result for the value of cmd:

func main() {
	sh := `upx c:\github.com\jftuga\test\test.exe`
	cmd, err := shellwords.Parse(sh)
	if err != nil {
		fmt.Println("err:", err)
		return
	}
	fmt.Println(cmd)
}

This outputs:

[upx c:github.comjftugatesttest.exe]

when it should output:

[upx c:\github.com\jftuga\test\test.exe]

Can this be fixed, please?

jftuga avatar Apr 24 '20 20:04 jftuga

https://github.com/mattn/go-shellwords/pull/39 is now pending review. I'd appreciate 👀 from any Windows user especially.

radeksimko avatar May 30 '20 21:05 radeksimko

What is the best way to test? If I run go get -u github.com/mattn/go-shellwords, will this download the version that needs to be tested or only the version listed on the GitHub Releases page?

jftuga avatar Jun 01 '20 11:06 jftuga

@jftuga You can install it from the forked repo, linking to the specific branch:

go get github.com/radeksimko/go-shellwords@b-windows-backslash

If you want to install from the specific commit on that branch at the time of writing:

go get github.com/radeksimko/go-shellwords@74d265b

Edit: This does not actually work, because the go.mod in the fork is not modified. You will get this error:

❯ go get github.com/radeksimko/go-shellwords@74d265b
go: downloading github.com/radeksimko/go-shellwords v1.0.11-0.20200530213150-74d265b60ebe
go: github.com/radeksimko/go-shellwords 74d265b => v1.0.11-0.20200530213150-74d265b60ebe
go get: github.com/radeksimko/[email protected]: parsing go.mod:
	module declares its path as: github.com/mattn/go-shellwords
	        but was required as: github.com/radeksimko/go-shellwords

makew0rld avatar Aug 28 '20 15:08 makew0rld

@makeworld-the-better-one

I ran:

git clone -b b-windows-backslash https://github.com/radeksimko/go-shellwords.git

I now get the correct result of:

[upx c:\github.com\jftuga\test\test.exe]

jftuga avatar Aug 28 '20 19:08 jftuga

@jftuga How did you import it for use in your code?

makew0rld avatar Aug 28 '20 20:08 makew0rld

package main

import (
	"fmt"
	"github.com/radeksimko/go-shellwords"
)

func main() {
	sh := `upx c:\github.com\jftuga\test\test.exe`
	cmd, err := shellwords.Parse(sh)
	if err != nil {
		fmt.Println("err:", err)
		return
	}
	fmt.Println(cmd)
}

jftuga avatar Aug 28 '20 20:08 jftuga

Sorry, what I'm wondering is where you cloned it, relative to that file, to to be able to use that import.

makew0rld avatar Aug 28 '20 20:08 makew0rld

cd /d C:\Go\src\github.com\radeksimko\
git clone -b b-windows-backslash https://github.com/radeksimko/go-shellwords.git

cd c:\github.com\jftuga\test
go build test.go
c:\github.com\jftuga\test>test.exe
[upx c:\github.com\jftuga\test\test.exe]

I am running: go version go1.15 windows/amd64

jftuga avatar Aug 28 '20 21:08 jftuga