-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Readd the empty userinfo to
url.href
(#226)
If the userinfo is present but empty, the parsed host is also empty, and `url.pathname` is not `'/'`, then readd the empty userinfo to `url.href`, otherwise the original invalid URL might be transformed into a valid one with `url.pathname` as host.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -771,6 +771,65 @@ describe('url-parse', function () { | |
assume(parsed.pathname).equals('/'); | ||
assume(parsed.href).equals('http://user%40:pas%3As%[email protected]/'); | ||
}); | ||
|
||
it('adds @ to href if auth and host are empty', function () { | ||
var parsed, i = 0; | ||
var urls = [ | ||
'http:@/127.0.0.1', | ||
'http::@/127.0.0.1', | ||
'http:/@/127.0.0.1', | ||
'http:/:@/127.0.0.1', | ||
'http://@/127.0.0.1', | ||
'http://:@/127.0.0.1', | ||
'http:///@/127.0.0.1', | ||
'http:///:@/127.0.0.1' | ||
]; | ||
|
||
for (; i < urls.length; i++) { | ||
parsed = parse(urls[i]); | ||
|
||
assume(parsed.protocol).equals('http:'); | ||
assume(parsed.auth).equals(''); | ||
assume(parsed.username).equals(''); | ||
assume(parsed.password).equals(''); | ||
assume(parsed.host).equals(''); | ||
assume(parsed.hostname).equals(''); | ||
assume(parsed.pathname).equals('/127.0.0.1'); | ||
assume(parsed.origin).equals('null'); | ||
assume(parsed.href).equals('http://@/127.0.0.1'); | ||
assume(parsed.toString()).equals('http://@/127.0.0.1'); | ||
} | ||
|
||
urls = [ | ||
'http:@/', | ||
'http:@', | ||
'http::@/', | ||
'http::@', | ||
'http:/@/', | ||
'http:/@', | ||
'http:/:@/', | ||
'http:/:@', | ||
'http://@/', | ||
'http://@', | ||
'http://:@/', | ||
'http://:@' | ||
]; | ||
|
||
for (i = 0; i < urls.length; i++) { | ||
parsed = parse(urls[i]); | ||
|
||
assume(parsed.protocol).equals('http:'); | ||
assume(parsed.auth).equals(''); | ||
assume(parsed.username).equals(''); | ||
assume(parsed.password).equals(''); | ||
assume(parsed.host).equals(''); | ||
assume(parsed.hostname).equals(''); | ||
assume(parsed.pathname).equals('/'); | ||
assume(parsed.origin).equals('null'); | ||
assume(parsed.href).equals('http:///'); | ||
assume(parsed.toString()).equals('http:///'); | ||
} | ||
}); | ||
}); | ||
|
||
it('accepts multiple ???', function () { | ||
|