Closed
Labels
enhancementIssue/PR: A new featureIssue/PR: A new featureoutdatedIssue/PR: Open for more than 3 monthsIssue/PR: Open for more than 3 months
Description
Python already parses URLs, and does it correctly:
>>> from urllib.parse import urlparse
>>> urlparse('https://google.com')
ParseResult(scheme='https', netloc='google.com', path='', params='', query='', fragment='')
>>> urlparse('gopher://gopher.waynewerner.com')
ParseResult(scheme='gopher', netloc='gopher.waynewerner.com', path='', params='', query='', fragment='')
>>> urlparse('tel://555-555-5555')
ParseResult(scheme='tel', netloc='555-555-5555', path='', params='', query='', fragment='')
>>> urlparse('file:///path-to-some-file')
ParseResult(scheme='file', netloc='', path='/path-to-some-file', params='', query='', fragment='')
>>> urlparse('missing-scheme.com')
ParseResult(scheme='', netloc='', path='missing-scheme.com', params='', query='', fragment='')
I had to chase down this library because click-params uses validators to validate URLs, but totally valid URLs aren't parsed correctly because the scheme wasn't expected by this library 😞
Reacted by Rob Emanuele
Metadata
Metadata
Assignees
Labels
enhancementIssue/PR: A new featureIssue/PR: A new featureoutdatedIssue/PR: Open for more than 3 monthsIssue/PR: Open for more than 3 months
Activity
rcirca commentedon Aug 11, 2021
It doesn't validate though, parses sure, but validating with it is not good. http:////.google.com would be considered valid based on urllib.
waynew commentedon Aug 11, 2021
You're right, it would, and is a valid URL:
path might not be a valid domain name, but that's an entirely different problem. Interestingly enough, http:////.google.com works fine if you type it into your address bar in Chrome, though it fails if you click that link. http:////google.com works, though.
rcirca commentedon Aug 12, 2021
well, technically it's wrong to place that for the 'path', google.com should be the 'netloc'?
Yeah, without the period it works fine in chrome, but not in safari 😅
waynew commentedon Aug 13, 2021
Well, it is the path, strictly speaking, and should be rejected because there is no netloc.
Just because it's a real URL doesn't mean you can get there from here 🤣
maint: improves `url` module
waynew commentedon Mar 19, 2023
Awesome! Thanks for your efforts 🎉🚀👍