78 lines
3.3 KiB
HTML
78 lines
3.3 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<script src="../../resources/js-test-pre.js"></script>
|
|
<script src="resources/utilities.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
description("Strip tabs and newlines according to URL spec: https://url.spec.whatwg.org/#concept-basic-url-parser");
|
|
|
|
var expectedGeneralizedResult = "scheme://username:password@host.name:5000/path?query#fragment";
|
|
generalizedCases = [
|
|
//normal case
|
|
["scheme://username:password@host.name:5000/path?query#fragment"],
|
|
//add tabs and newlines at scheme
|
|
["\\tsch\\neme\\r://username:password@host.name:5000/path?query#fragment"],
|
|
//add tabs and newlines after scheme
|
|
["scheme:\\t/\\n/username:password@host.name:5000/path?query#fragment"],
|
|
//add tabs and newlines at credential
|
|
["scheme://\\tuser\\rname\\n:\\rpassw\\nord\\t@host.name:5000/path?query#fragment"],
|
|
//add tabs and newlines at host
|
|
["scheme://username:password@\\tho\\nst\\r.\\tna\\nme\\r:5000/path?query#fragment"],
|
|
//add tabs and newlines at port
|
|
["scheme://username:password@host.name:\\t5\\n000\\r/path?query#fragment"],
|
|
//add tabs and newlines at path
|
|
["scheme://username:password@host.name:5000/\\tpa\\nth\\r?query#fragment"],
|
|
//add tabs and newlines at query
|
|
["scheme://username:password@host.name:5000/path?\\tqu\\nery\\r#fragment"],
|
|
//add tabs and newlines at fragment
|
|
["scheme://username:password@host.name:5000/path?query#\\tfr\\nagment\\r"],
|
|
];
|
|
|
|
for (var i = 0; i < generalizedCases.length; ++i)
|
|
shouldBe("canonicalize('" + generalizedCases[i] + "')",
|
|
"'" + expectedGeneralizedResult + "'");
|
|
|
|
specialCases = [
|
|
//http & https
|
|
["\\tht\\ntp\\r://www.example.com/", "http://www.example.com/"],
|
|
["\\tht\\ntps\\r://www.example.com/", "https://www.example.com/"],
|
|
//file URL
|
|
["\\tfi\\nle\\r:///var/tmp", "file:///var/tmp"],
|
|
["file://\\n/v\\tar\\r/\\ttm\\np\\r", "file:///var/tmp"],
|
|
//ipv4, ipv6
|
|
["http://\\n12\\r7\\t.0.0.1\\t/", "http://127.0.0.1/"],
|
|
["http://\\n[\\r200\\t1\\r:\\t5:\\n:042:44::0370:7334\\r]\\t/", "http://[2001:5::042:44::0370:7334]/"],
|
|
//localhost
|
|
["http://\\tlo\\ncalhost\\r", "http://localhost/"],
|
|
//relative path
|
|
["\\t/\\n/\\rsch\\teme\\n/relative\\r", "file://scheme/relative"],
|
|
["\\t/\\npa\\rth\\t/\\nabsolute\\r", "file:///path/absolute"],
|
|
//data URL
|
|
["\\td\\nata\\r:image/png;base64,invalidData", "data:image/png;base64,invalidData"],
|
|
["data:\\tim\\rage/png\\n;\\tbas\\ne64\\r,\\tinv\\nalidData\\r", "data:image/png;base64,invalidData"],
|
|
//javascript URL
|
|
["\\tjav\\nascript\\r:alert(1);", "javascript:alert(1);"],
|
|
["javascript:\\tal\\rert\\n(\\n1)\\t;\\r", "javascript:alert(1);"],
|
|
];
|
|
|
|
for (var i = 0; i < specialCases.length; ++i)
|
|
shouldBe("canonicalize('" + specialCases[i][0] + "')",
|
|
"'" + specialCases[i][1] + "'");
|
|
|
|
// relative path scheme less URL
|
|
var URLParts = window.location.href.split( '/' );
|
|
var path = URLParts[0];
|
|
var len = URLParts.length - 1;
|
|
for (i = 1; i < len; i++)
|
|
path += "/" + URLParts[i];
|
|
|
|
var relativePathSchemeLessURL = "\tpa\nth\r/\trelative/\nscheme/less\r";
|
|
var expectedRelativePathSchemeLessURL = path + "/path/relative/scheme/less";
|
|
shouldBe("canonicalize(relativePathSchemeLessURL)", "expectedRelativePathSchemeLessURL");
|
|
</script>
|
|
<script src="../../resources/js-test-post.js"></script>
|
|
</body>
|
|
</html>
|