Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

/* Any copyright is dedicated to the Public Domain.
"use strict";
function canonicalize(url) {
let urlUtils = Cc["@mozilla.org/url-classifier/utils;1"].getService(
Ci.nsIUrlClassifierUtils
);
let uri = Services.io.newURI(url);
return uri.scheme + "://" + urlUtils.getKeyForURI(uri);
}
function run_test() {
// These testcases are from
equal(canonicalize("http://host/%25%32%35"), "http://host/%25");
equal(canonicalize("http://host/%2525252525252525"), "http://host/%25");
equal(
canonicalize("http://host/%%%25%32%35asd%%"),
);
equal(canonicalize("http://www.google.com/"), "http://www.google.com/");
equal(
canonicalize(
),
);
equal(
canonicalize(
),
);
equal(
canonicalize("http://www.google.com/blah/.."),
);
equal(
);
equal(canonicalize("http://www.GOOgle.com/"), "http://www.google.com/");
equal(canonicalize("http://www.google.com.../"), "http://www.google.com/");
equal(
);
equal(canonicalize("http://www.google.com/q?"), "http://www.google.com/q?");
equal(
canonicalize("http://www.google.com/q?r?"),
);
equal(
canonicalize("http://www.google.com/q?r?s"),
);
equal(canonicalize("http://evil.com/foo;"), "http://evil.com/foo;");
equal(canonicalize("http://evil.com/foo?bar;"), "http://evil.com/foo?bar;");
equal(
canonicalize("http://notrailingslash.com"),
);
equal(
);
equal(
canonicalize("https://www.securesite.com/"),
);
equal(
);
equal(
);
equal(
canonicalize(
),
);
}