Skip to content

Make argument quotation compatible with cygwin/msys2/gitbash on Windows #97

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arixmkii
Copy link
Contributor

It is the same situation like in https://github.com/lima-vm/lima/blob/786c1f5f3c6e8ff276c0c5d6789cdd9243d70f49/pkg/sshutil/sshutil.go#L271

Windows based tooling can't correctly escape ".

The implemented workaround probably will not work for some extreme cases, but at least it is not failing outright from the start.

It has been tested to work on Windows with Git Bash and WSL2 based tooling.

Signed-off-by: Arthur Sengileyev <arthur.sengileyev@gmail.com>
@arixmkii
Copy link
Contributor Author

@AkihiroSuda could you take a look?

@@ -252,6 +252,16 @@ func (rsf *ReverseSSHFS) Start() error {
return nil
}

func addQuotes(input string) string {
input = strconv.Quote(input)
if runtime.GOOS == "windows" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment to explain the reason?

Also, can we have a unit test and/or an integration test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to sketch the unit test. It will take some time, I will ping you, when it is done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I managed to get a reproducer with a command line example. The command is extracted using recording processes started on the host.

"C:\Program Files\Git\usr\bin\ssh.exe" -i /c/Users/User/.local/share/containers/podman/machine/machine -p 60251 core@localhost -- mkdir -p \"/c/Users/runneradmin\"
bash: -c: line 1: unexpected EOF while looking for matching `"'

I don't think this can be reasonably covered by integration test - this would recover spinning VM just for that test.

And the method in question is not unit testable as it actually executes the resulting external commands within itself.

It would be only possible to cover private addQuotes with a unit test, which is actually a single standard library call on all platforms other than Windows, but I will add it and add the comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants