blob: 2938de89c5f699e68ed6a425445c6a844b0440b8 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="resources/utilities.js"></script>
</head>
<body>
<script>
description("Canonicalization of URLs that start with something that may or may not be userinfo");
cases = [
// These cases currently match between WebKit and Gecko, so the results should probably never change.
["http:@www.apple.com", "http://www.apple.com/", ["http:","www.apple.com","","/","",""]],
["http:/@www.apple.com", "http://www.apple.com/", ["http:","www.apple.com","","/","",""]],
["http://@www.apple.com", "http://www.apple.com/", ["http:","www.apple.com","","/","",""]],
["http:a:b@www.apple.com", "http://a:b@www.apple.com/", ["http:","www.apple.com","","/","",""]],
["http:/a:b@www.apple.com", "http://a:b@www.apple.com/", ["http:","www.apple.com","","/","",""]],
["http://a:b@www.apple.com", "http://a:b@www.apple.com/", ["http:","www.apple.com","","/","",""]],
["http://@pple.com", "http://pple.com/", ["http:","pple.com","","/","",""]],
["http::b@www.apple.com", "http://:b@www.apple.com/", ["http:","www.apple.com","","/","",""]],
["http:/:b@www.apple.com", "http://:b@www.apple.com/", ["http:","www.apple.com","","/","",""]],
["http://:b@www.apple.com", "http://:b@www.apple.com/", ["http:","www.apple.com","","/","",""]],
// Gecko and WebKit both treat this URLs as invalid, but Gecko reports "http:" as protocol.
["http:/:@/www.apple.com", "http:/:@/www.apple.com", [":","","","","",""]],
// HTTP URLs with an empty host are invalid, because otherwise, there is just too much risk that another parsing pass (possibly by a network layer with a subtly different algorithm) would treat path as hostname.
["http://user@/www.apple.com", "http://user@/www.apple.com", [":","","","","",""]], // Regression test for <https://bugs.webkit.org/show_bug.cgi?id=57220>.
["http:@/www.apple.com", "http:@/www.apple.com", [":","","","","",""]], // Regression test for <https://bugs.webkit.org/show_bug.cgi?id=104919>.
["http:/@/www.apple.com", "http:/@/www.apple.com", [":","","","","",""]],
["http://@/www.apple.com", "http://@/www.apple.com", [":","","","","",""]],
["https:@/www.apple.com", "https:@/www.apple.com", [":","","","","",""]], // Regression test for <https://bugs.webkit.org/show_bug.cgi?id=104919>.
["http:a:b@/www.apple.com", "http:a:b@/www.apple.com", [":","","","","",""]],
["http:/a:b@/www.apple.com", "http:/a:b@/www.apple.com", [":","","","","",""]],
["http://a:b@/www.apple.com", "http://a:b@/www.apple.com", [":","","","","",""]],
// Gecko treats this URL as relative. WebKit treats it as invalid, because of empty host.
["http::@/www.apple.com", "http::@/www.apple.com", [":","","","","",""]],
// Empty password. Gecko still adds a ':', WebKit does not.
["http:a:@www.apple.com", "http://a@www.apple.com/", ["http:","www.apple.com","","/","",""]],
["http:/a:@www.apple.com", "http://a@www.apple.com/", ["http:","www.apple.com","","/","",""]],
["http://a:@www.apple.com", "http://a@www.apple.com/", ["http:","www.apple.com","","/","",""]],
// Some tests for multiple @-signs. WebKit treats these URLs as invalid, while Gecko allows '@' in userinfo, searching for the last instance in authority as a delimiter.
["http://a:b@www.@pple.com/p@th", "http://a:b@www.@pple.com/p@th", [":","","","","",""]],
["http://www.@@pple.com", "http://www.@@pple.com", [":","","","","",""]],
["http://@@pple.com", "http://@@pple.com", [":","","","","",""]],
["http://@@@pple.com", "http://@@@pple.com", [":","","","","",""]],
["http:@@/www.apple.com", "http:@@/www.apple.com", [":","","","","",""]],
["http:/@@/www.apple.com", "http:/@@/www.apple.com", [":","","","","",""]],
["http://@@/www.apple.com", "http://@@/www.apple.com", [":","","","","",""]],
["http:@:b@www.apple.com", "http:@:b@www.apple.com", [":","","","","",""]],
["http:/@:b@www.apple.com", "http:/@:b@www.apple.com", [":","","","","",""]],
["http://@:b@www.apple.com", "http://@:b@www.apple.com", [":","","","","",""]],
// Gecko escapes '.' in username, WebKit does not.
["http://www.@pple.com", "http://www.@pple.com/", ["http:","pple.com","","/","",""]],
// Invalid in WebKit. Gecko thinks that hostname is ":www.apple.com", which doesn't seem like a good idea.
["http:@:www.apple.com", "http:@:www.apple.com", [":","","","","",""]],
["http:/@:www.apple.com", "http:/@:www.apple.com", [":","","","","",""]],
["http://@:www.apple.com", "http://@:www.apple.com", [":","","","","",""]],
// Invalid in Gecko. WebKit just treats this as a URL with empty username and password, which appears to make sense.
["http://:@www.apple.com", "http://www.apple.com/", ["http:","www.apple.com","","/","",""]],
// Host is empty, but hostname is not, so the resulting parsed URL string is not particularly ambiguous.
// Gecko builds the same parsed URL string, although its components are different.
// FIXME: Unsure why we are getting a "0" as port here, but it probably doesn't matter for such an edge case.
["http:@:/www.apple.com", "http://:/www.apple.com", ["http:","","0","/www.apple.com","",""]],
["http:/@:/www.apple.com", "http://:/www.apple.com", ["http:","","0","/www.apple.com","",""]],
["http://@:/www.apple.com", "http://:/www.apple.com", ["http:","","0","/www.apple.com","",""]],
["http:@:80/www.apple.com", "http://:80/www.apple.com", ["http:","","80","/www.apple.com","",""]],
];
for (var i = 0; i < cases.length; ++i) {
var test_string = cases[i][0];
var expected_canonicalized_url = cases[i][1];
var expected_url_segments = cases[i][2];
shouldBe("canonicalize('" + test_string + "')", "'" + expected_canonicalized_url + "'");
shouldBe("segments('" + test_string + "')", "'" + JSON.stringify(expected_url_segments) + "'");
debug("");
}
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>