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: use URL instead of url.parse #141

Merged
merged 2 commits into from
Sep 5, 2023
Merged

fix: use URL instead of url.parse #141

merged 2 commits into from
Sep 5, 2023

Conversation

wraithgar
Copy link
Member

No description provided.

@wraithgar wraithgar requested a review from a team as a code owner August 24, 2023 21:59
res.fetchSpec = parsedUrl.toString()
}
if (res.fetchSpec.startsWith('git+')) {
res.fetchSpec = res.fetchSpec.slice(4)
Copy link
Member Author

Choose a reason for hiding this comment

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

protocol is not able to be changed in a URL instance like it was in a url.parse result.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that might be related to nodejs/node#49319 - it's supposed to be changeable.

Copy link
Member Author

Choose a reason for hiding this comment

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

file: is a special spec so changing from git+file: (non special) to file: (special) appears to be forbidden.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, it seems that the spec forbids it, but all browsers allow it, which means the spec will likely change to allow it.

Copy link
Member Author

@wraithgar wraithgar Aug 25, 2023

Choose a reason for hiding this comment

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

Browsers do not obey the spec and also break in fun ways when you do change the spec

Firefox:

x = new URL("git+file://a")
URL { href: "git+file://a", origin: "null", protocol: "git+file:", username: "", password: "", host: "", hostname: "", port: "", pathname: "//a", search: "" }

x.toString()
"git+file://a"
x.protocol = "file:"
"file:"
x.toString()
"file:///"  

Node silently ignores the setter with no warnings or errors (which I suppose is to spec since it just says return).

node.js

> x = new URL('git+file://a')
URL {
  href: 'git+file://a',
  origin: 'null',
  protocol: 'git+file:',
  username: '',
  password: '',
  host: 'a',
  hostname: 'a',
  port: '',
  pathname: '',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}
> x.toString()
'git+file://a'
> x.protocol = 'file:'
'file:'
> x.protocol
'git+file:'
> x.toString()
'git+file://a'

Copy link
Contributor

Choose a reason for hiding this comment

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

lol, that is fun. the .protocol accessor correctly updates tho, even if the double slashes and default port behavior ends up being inconsistent.

(obv none of this helps this particular migration)

}
delete urlparse.hash
res.fetchSpec = url.format(urlparse)
parsedUrl.hash = ''
Copy link
Member Author

Choose a reason for hiding this comment

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

delete does not work on the URL instance's hash attribute like it did with url.parse

} else {
setGitCommittish(res, urlparse.hash != null ? urlparse.hash.slice(1) : '')
Copy link
Member Author

Choose a reason for hiding this comment

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

the hash attribute of a URL instance is always set to a string object.

lib/npa.js Outdated
}
} else if (rawSpec.startsWith('git+file://')) {
// URL can't handle windows paths
const noProtocol = rawSpec.slice(11).replace(/\\/g, '/')
Copy link
Member Author

Choose a reason for hiding this comment

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

This is leftover from when I was also trying to get the drive letter stuff fixed here. That ended up not being needed so stripping the protocol here is unneeded as it does not ever contain backslashes.

It does more than set one attribute, and shouldn't need to return res if it' mutating in place
Copy link
Contributor

@lukekarrys lukekarrys left a comment

Choose a reason for hiding this comment

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

It would be interesting to see what sort of overlap there could potentially be with the url parsing in hosted-git-info (particularly https://github.com/npm/hosted-git-info/blob/1cfe4e8bb2c9373eeb84f2d94ddad6abc000f6f8/lib/parse-url.js)

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