sindresorhus / normalize-url

Normalize a URL
MIT License
837 stars 123 forks source link

Incorrect URL returned when protocol is missing #187

Closed dawidmohr closed 6 months ago

dawidmohr commented 8 months ago

I wanted to use normalize-url in my project, but I noticed a problem

In the documentation, one of the examples does not work (the one I need :))

normalizeUrl('sindresorhus.com:123', {
    removeExplicitPort: true
});
//=> 'http://sindresorhus.com'
t.is(normalizeUrl('sindresorhus.com:123', options), 'http://sindresorhus.com');

The test returned: 'sindresorhus.com:123' so there is an issue

I looked at the code and noticed that the hasCustomProtocol function returns the wrong value

So I prepared a quick fix, but I'm not a URL specialist, my PR is rather illustrative, so feel free to close it https://github.com/sindresorhus/normalize-url/pull/186

My thought was that there are no dots in the protocol, and there is always a dot between the domain name and the TLD, so did this