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

Fix cannot open url contains | on windows #98

Closed
wants to merge 2 commits into from

Conversation

baoti
Copy link

@baoti baoti commented Jul 6, 2018

  • If contains space, DO NOT escape;
  • otherwise, DO escape.
  • No matter target is URL, or file path.
  • Escape Character: & \ < > ^ |

Detail in #74 (comment).

@sindresorhus
Copy link
Owner

Can you link to some documentation about this?

@baoti
Copy link
Author

baoti commented Jul 6, 2018

Oh, I found https://ss64.com/nt/syntax-esc.html, look at the Escape Character section.

Escape Character
  ^  Escape character.
Adding the escape character before a command symbol allows it to be treated as ordinary text. 
When piping or redirecting any of these charcters you should prefix with the escape character: & \ < > ^ |

 e.g.  ^\  ^&  ^|  ^>  ^<  ^^ 

@baoti
Copy link
Author

baoti commented Jul 6, 2018

@sindresorhus Do you want me replace all those characters?

\
&
|
>
<
^

@sindresorhus
Copy link
Owner

What do you think about #74 (comment) ? If it works, it would be better.

@baoti
Copy link
Author

baoti commented Jul 6, 2018

OK, I‘d like to work on it.

@baoti
Copy link
Author

baoti commented Jul 10, 2018

@sindresorhus I add many test results in #74 (comment).

I think these test cases is useful to position the issue #74.

@sindresorhus
Copy link
Owner

@baoti Still interested in handling #98 (comment)?

@baoti
Copy link
Author

baoti commented Jun 12, 2019

@sindresorhus As #74 (comment) said, wrapping it in double quotes doesn't help. What do you want handling?

@Cossey
Copy link

Cossey commented Jun 12, 2019

I think @baoti's approach mentioned here would be the best way forward. What an annoying quirk!

@sindresorhus
Copy link
Owner

Alright, let's try out this then:

If contains space, DO NOT escape;
otherwise, DO escape.

@@ -33,7 +33,9 @@ module.exports = (target, opts) => {
} else if (process.platform === 'win32' || isWsl) {
cmd = 'cmd' + (isWsl ? '.exe' : '');
args.push('/c', 'start', '""', '/b');
target = target.replace(/&/g, '^&');
if (target.indexOf(' ') === -1) {
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
if (target.indexOf(' ') === -1) {
if (!target.includes(' ')) {

Copy link
Owner

Choose a reason for hiding this comment

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

Can you also link to #74 (comment) in a code comment to clarify what it does and why.

@sindresorhus
Copy link
Owner

@baoti Can you fix the merge conflict?

@baoti
Copy link
Author

baoti commented Jul 1, 2019

@sindresorhus I got the reason for doing not escape which contains space char. The argument would be wrapped in double quotes. See source for detail.

We can pass childProcessOptions.windowsVerbatimArguments = true to disable it, and always escape target by double quotes.

@sindresorhus
Copy link
Owner

Good find. Let’s do that then.

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.

3 participants