bug: Parse function removes needed backslashes
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?
https://github.com/mattn/go-shellwords/pull/39 is now pending review. I'd appreciate 👀 from any Windows user especially.
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 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
@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 How did you import it for use in your code?
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)
}
Sorry, what I'm wondering is where you cloned it, relative to that file, to to be able to use that import.
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