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

host + port is recognised as protocol #70

Closed
danielroe opened this issue Jul 29, 2022 · 5 comments · Fixed by #124
Closed

host + port is recognised as protocol #70

danielroe opened this issue Jul 29, 2022 · 5 comments · Fixed by #124
Labels
bug Something isn't working

Comments

@danielroe
Copy link
Member

hasProtocol('localhost:3000')
// true
@pi0
Copy link
Member

pi0 commented Jul 29, 2022

How do you think about solution? Technically something like mailto:3000@example.com is also valid protocol.

@divine
Copy link
Contributor

divine commented Aug 22, 2022

Hello,

Probably the correct way of detecting protocols would be to get that from IANA list but the issue is that there are lot of unknown protocols.

https://en.m.wikipedia.org/wiki/List_of_URI_schemes

URL.protocol returns localhost: as protocol as well.

Thanks!

@pi0
Copy link
Member

pi0 commented Aug 22, 2022

Good point about URL behavior and known schemes @divine. But indeed we have lots of 3rd party and unlisted protocols. Let me add data: and node: to the list.

We could try to have a smart regex that detects host:port only inputs BTW. (Because ufo utils, accept more than URL possible values and special values like this are kinda allowed)

@shtse8
Copy link

shtse8 commented Aug 25, 2022

How do you think about solution? Technically something like mailto:3000@example.com is also valid protocol.

this is valid urn protocol, but not uri, maybe we can allow user to specific uri or urn in hasProtocol options? Probably it's hard to do it in smart way.

tested with urijs (the largest uri package in npm), same issue found.

new URI('localhost:3000').protocol()
// 'localhost'

@pi0
Copy link
Member

pi0 commented Aug 25, 2022

This kind of input is basically host (${hostname}:${port}) which we implicitly accept as valid input for various ufo utils. Sticking with a strict URL parser, it is true that behavior returns localhost as a scheme but this is kinda the DX point of ufo utils over using raw URL to allow more versatility on common inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants