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
Special parsing for git's not-really-urls containing scp host specifiers #2990
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an example of a URL that would be incorrectly parsed?
static npmUrlToGitUrl(npmUrl: string): GitUrl { | ||
// Special case in npm, where ssh:// prefix is stripped to pass scp-like syntax | ||
// which works as remote path only if there are no slashes before ':' | ||
const match = npmUrl.match(/^git\+ssh:\/\/((?:[^@:\/]+@)?([^@:\/]+):.*)/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can git URLs have a password, ie. foo:bar@example.org
? This regex doesn't catch this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intentional. In scp host specifiers there is no password.
Git manual (man git-clone
) specifies it as [user@]host.xz:/~[user]/path/to/repo.git/
, although relative paths are also supported (scp man page documents the syntax as [[user@]host1:]file
)
The scp urls are in the test. The format is
|
@arcanis Thanks for the review. Is there anything else that needs to be done? |
Just one question: I see you're using |
I changed static methods only because it was necessary, but kept constructor as-is to make the change smaller. But it makes sense to have them all consistently take the same type of URL, so I've made that change. I've rebased on master to avoid a merge conflict. |
Thanks for the rebase 👍 |
What git calls a URL is not strictly a URL, but a union of URLs and "scp host specifiers" (
host:path
). The syntax can't be treated as a regular URL, because hostname of scp hostname specifiers parses as a URL scheme.This removes the previous workaround (
transformUrl
, #573), which was transforming scp host specifiers to ssh:// URLs. This wasn't compatible with npm, as it changed semantics of the URL and caused git to ignore SSH host aliases (#1796).The previous workaround also accidentally disabled
hasArchiveCapability
check — the regex inhasArchiveCapability
expected:
as a way to detect scp host specifiers. Since scp goes over SSH, I assume the check can be generalized to check for the SSH protocol, so I've made that explicit.To make it clear that git "URLs" are not real URLs, I've created a new type for them. I also use the new type to store a couple of precomputed properties that used to be extracted from the URL (the
protocol
had to be stored explicitly anyway because of the git "URL" parsing ambiguity).