Skip to content
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

Quoting of argument is not working correctly when adding wslpath #91

Closed
carlolars opened this issue Oct 28, 2019 · 3 comments
Closed

Quoting of argument is not working correctly when adding wslpath #91

carlolars opened this issue Oct 28, 2019 · 3 comments

Comments

@carlolars
Copy link
Contributor

When injecting wslpath in an argument then the argument to wslpath is quoted with single-quotes, this cause the argument be considered as "already quoted" at

if arg.contains(quote_characters) {
and no quotes are added around the argument even if actually needed. Simple test below:

>wslgit.exe -c "test.value=C:\Program Files (x86)\SmartGit" config test.value
bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `git -c test.value=/c/Program Files (x86)/SmartGit config test.value'
# missing quotes!         ^                                        ^

The quoting of arguments must become smarter, maybe ignore the quotes found in $(wslpath ...)

@carlolars
Copy link
Contributor Author

When are quotes actually used?
Quoting is used on the command line when an argument string contains for example spaces to prevent the shell from splitting the string in several arguments. The shell (cmd.exe or PowerShell) then passes the argument string(s) to the process as an array of strings without the quotes.
When invoking a process directly without using a shell then the arguments are passed as an array of strings and no quoting is required.

So wslgit.exe should never get arguments that contain quotes, unless someone really wants a literal " and pass them using \", if so they should be passed to the WSL side correctly escaped.

@andy-5 What do you think? I have implemented a possible fix for this, I'll push it for review.

@andy-5
Copy link
Owner

andy-5 commented Nov 8, 2019

I think your line of thought is correct. If there are quotes in arguments, they are explicitly added as you described, so wslgit should escape them again.
Your PR looks fine, though I haven't actually tested it. I guess it fixes the example given above? Can we close this issue, or should we wait and test it for longer before closing?

@carlolars
Copy link
Contributor Author

Yes the PR fixes the example above.
I've used a build with this fix for over a week at work and home without any errors so I don't think that my usage pattern will be able to find any errors.

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

No branches or pull requests

2 participants