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

Windows paths with forward-slashes broke in v7.2.0 #214

Closed
abythell opened this issue Jan 14, 2021 · 2 comments · Fixed by #220
Closed

Windows paths with forward-slashes broke in v7.2.0 #214

abythell opened this issue Jan 14, 2021 · 2 comments · Fixed by #220

Comments

@abythell
Copy link

#188 introduced Powershell and a new method for encoding arguments. By wrapping the target in, "double quote with double quotes to ensure the inner quotes are passed through", paths with forward slashes on Windows no longer get reinterpreted as they did before, causing open to fail.

I believe this to also be the cause of sindresorhus/open-cli#16 as open-cli@6.0.1 works on Windows with a target path like dist\report.html but not with dist/report.html, unlike earlier versions which worked with both.

Currently, target has slashes and backticks added to it before encoding:

// target = 'dist/report.html'
encodedArguments.push(`"\`"${target}\`""`); // result: "`"dist/report.html`""

... which doesn't actually result in the file being opened. If instead the target is passed as-is:

// target = 'dist/report.html'
encodedArguments.push(target); // result: dist/report.html

...then open works as expected.

Of course, this isn't a proper solution, because I'm sure those quotes and ticks are being inserted for a purpose, but this hopefully demonstrates the issue for someone else with a better understanding of Powershell.

@sindresorhus
Copy link
Owner

// @tim-stasse

@kuzalekon
Copy link
Contributor

@abythell @sindresorhus
I made some tests of Start command in PowerShell:

// With escaped quotation character
Start "`"Path\filename.ext`""                  // OK
Start "`"Path/filename.ext`""                  // Error
Start "`"Path with spaces\filename.ext`""      // OK
Start "`"Path with spaces/filename.ext`""      // Error

// Without escaped quotation character
Start "Path\filename.ext"                      // OK
Start "Path/filename.ext"                      // OK
Start "Path with spaces\filename.ext"          // OK
Start "Path with spaces/filename.ext"          // OK

As you can see, if we add an escaped " character and use / as a separator in the path we will get an error.
The fact is that when passing the path of a filename/link with spaces for opening, we do not need to additionally add a " character as it is now done in the string.
Therefore, the fix for this bug will be simple - need to remove the addition of escaped quotation marks for the target.
I made a micro PR for that - #220.

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

Successfully merging a pull request may close this issue.

3 participants