Throwing error on given `view-source:` url string
Closed this issue · 1 comments
mebble commented
const normalize = require('normalize-url');
const n = normalize('view-source:https://github.com/sindresorhus/normalize-url/blob/master/index.js')
throws the error:
Thrown:
TypeError [ERR_INVALID_URL]: Invalid URL: http:view-source:https://github.com/sindresorhus/normalize-url/blob/master/index.js
at onParseError (internal/url.js:243:9)
at new URL (internal/url.js:319:5)
at normalizeUrl
[....]
{
input: 'http:view-source:https://github.com/sindresorhus/normalize-url/blob/master/index.js',
code: 'ERR_INVALID_URL'
}
Is this intentionally an error? Seems unintentional to me because it first prepends http
to the input, turning it into 'http:view-source:https://...
and then leaving it to the URL
function to handle it, if I'm correct.
It would be awesome if we could have view-source
urls handled by this module itself. Either define a normalisation result for view-source
like how it's done for data urls, or return a clear error message.
sindresorhus commented
I agree the error could be better (PR welcome for that), but I'm not interested in supporting lots of random protocols.