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

Support parsing url with ssh protocol in url.URL. #36172

Closed
LvChengbin opened this issue Nov 19, 2020 · 4 comments
Closed

Support parsing url with ssh protocol in url.URL. #36172

LvChengbin opened this issue Nov 19, 2020 · 4 comments
Labels
whatwg-url Issues and PRs related to the WHATWG URL implementation.

Comments

@LvChengbin
Copy link

> const { URL } = require( 'url' );
undefined
> new URL( 'ssh://git@github.com:nodejs/node.git' );
Uncaught TypeError [ERR_INVALID_URL]: Invalid URL: ssh://git@github.com:nodejs/node.git
    at onParseError (internal/url.js:256:9)
    at new URL (internal/url.js:332:5)
    at repl:1:1
    at Script.runInThisContext (vm.js:132:18)
    at REPLServer.defaultEval (repl.js:472:29)
    at bound (domain.js:430:14)
    at REPLServer.runBound [as eval] (domain.js:443:12)
    at REPLServer.onLine (repl.js:794:10)
    at REPLServer.emit (events.js:326:22)
    at REPLServer.EventEmitter.emit (domain.js:486:12) {
  input: 'ssh://git@github.com:nodejs/node.git',
  code: 'ERR_INVALID_URL'
}

The URL method cannot parse URLs formatted like ssh://git@github.com:nodejs/node.git, because the :nodejs part is regarded as an invalid port number, but in Google Chrome, the url is able to be parsed, the :nodejs part is legal if the protocol is not http, ftp, ws, etc.

Because of this issue, a url for git repository cannot be parsed directly, does it make sense to implement the method same as Google Chrome?

@aduh95
Copy link
Contributor

aduh95 commented Nov 19, 2020

For reference, in Chromium DevTools, it is parsed as:

URL {
hash: ""
host: ""
hostname: ""
href: "ssh://git@github.com:nodejs/node.git"
origin: "null"
password: ""
pathname: "//git@github.com:nodejs/node.git"
port: ""
protocol: "ssh:"
search: ""
searchParams: URLSearchParams {}
username: ""
}

In Firefox, it throws TypeError: URL constructor: ssh://git@github.com:nodejs/node.git is not a valid URL..

In Safari, it throws TypeError: Type error.

@aduh95 aduh95 added the whatwg-url Issues and PRs related to the WHATWG URL implementation. label Nov 19, 2020
@jasnell
Copy link
Member

jasnell commented Nov 19, 2020

So this is actually a limitation of the WHATWG URL parse algorithm, which the Chrome parser is actually not fully compliant to. What I would recommend here is opening an issue in the https://github.com/whatwg/url repo to see what can be done about this in the standard. Once it is addressed there (if it is addressed there) we can look at fixing it here.

/cc @annevk @domenic

@annevk
Copy link

annevk commented Nov 19, 2020

This would be considered a bug in Chrome. Glad that Firefox, Safari, and Node.js all seem to do the correct thing.

@watilde
Copy link
Member

watilde commented Nov 25, 2020

This was great finding for Chrome and we can close this issue as wrong repository. To continue the discussion if URL should support ssh protocol, we can move to https://github.com/whatwg/url as @jasnell recommended. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

No branches or pull requests

5 participants