<commit_before>var url = require("./url");

var sourceHTTP = "http://www.some.website.com/";
var sourceHTTPS = "https://www.some.website.com/";

var queryAndFragment = "?some=parameter&some-other=parameter;a=parameter-with-?-in-it#some-fragment";

var httpTargetUrl = "http://redirection.target.com/";
var httpTargetClean = httpTargetUrl + queryAndFragment;
var httpTargetEncoded = encodeURIComponent(httpTargetClean);
var httpTargetDoubleEncoded = encodeURIComponent(httpTargetEncoded);

var httpTarget = {
    clean: httpTargetClean,
    encoded: httpTargetEncoded,
    doubleEncoded: httpTargetDoubleEncoded,
};

var wwwTargetUrl = "www.redirection.target.com/";
var wwwTargetClean = wwwTargetUrl + queryAndFragment;
var wwwTargetEncoded = encodeURIComponent(wwwTargetClean);
var wwwTargetDoubleEncoded = encodeURIComponent(wwwTargetEncoded);

var wwwTarget = {
    clean: wwwTargetClean,
    encoded: wwwTargetEncoded,
    doubleEncoded: wwwTargetDoubleEncoded,
};

var noRedirectUrls = [
    httpTargetClean,
    sourceHTTP + wwwTargetClean.replace("www.", "www"),
    sourceHTTP + "/login?continue=" + httpTargetClean + "#some-fragment",
    sourceHTTP + "/login?continue=" + httpTargetEncoded + "#some-fragment",
    sourceHTTP + "/login?continue=" + httpTargetDoubleEncoded + "#some-fragment]",
];
var noRedirectTests = [for (url of noRedirectUrls) ["no", url, url]];

function pathTest(id, source, target, expected) {
    return [
        ["pa01" + id, source + target.clean, expected],
        ["pa02" + id, source + target.encoded, expected],
        ["pa03" + id, source + target.doubleEncoded, expected],

        ["pa04" + id, source + "/?" + target.clean, expected],
        ["pa05" + id, source + "/?" + target.encoded, expected],
        ["pa06" + id, source + "/?" + target.doubleEncoded, expected],
    ];
}

function cleanQueryTest(id, source, target, expected) {
    return [
        ["cqu01" + id, source + "/?target=" + target.clean, expected],
        ["cqu02" + id, source + "/?target=" + target.clean + "&some=parameter", expected],
        ["cqu03" + id, source + "/?target=" + target.clean + ";some=parameter", expected],
        ["cqu04" + id, source + "/?target=" + target.clean + "#some-fragment", expected],
    ];
}

function queryTest(id, source, target, expected) {
    return [
        ["qu01" + id, source + "/?target=" + target.encoded, expected],
        ["qu02" + id, source + "/?target=" + target.encoded + "&some=parameter", expected],
        ["qu03" + id, source + "/?target=" + target.encoded + ";some=parameter", expected],
        ["qu04" + id, source + "/?target=" + target.encoded + "#some-fragment", expected],

        ["qu05" + id, source + "/?target=" + target.doubleEncoded, expected],
        ["qu06" + id, source + "/?target=" + target.doubleEncoded + "&some=parameter", expected],
        ["qu07" + id, source + "/?target=" + target.doubleEncoded + ";some=parameter", expected],
        ["qu08" + id, source + "/?target=" + target.doubleEncoded + "#some-fragment", expected],
    ];
}

var otherTests = [
];

exports["test redirects"] = function(assert) {
    var tests =
        noRedirectTests
            .concat(pathTest("http",        sourceHTTP,  httpTarget, httpTargetClean))
            .concat(pathTest("www",         sourceHTTP,  wwwTarget,  "http://" + wwwTargetClean))
            .concat(pathTest("https",       sourceHTTPS, httpTarget, httpTargetClean))
            .concat(pathTest("wwws",        sourceHTTPS, wwwTarget,  "http://" + wwwTargetClean))
            .concat(queryTest("http",       sourceHTTP,  httpTarget, httpTargetClean))
            .concat(queryTest("www",        sourceHTTP,  wwwTarget,  "http://" + wwwTargetClean))
            .concat(queryTest("https",      sourceHTTPS, httpTarget, httpTargetClean))
            .concat(queryTest("wwws",       sourceHTTPS, wwwTarget,  "http://" + wwwTargetClean))
            .concat(cleanQueryTest("http",  sourceHTTP,  httpTarget, httpTargetUrl))
            .concat(cleanQueryTest("www",   sourceHTTP,  wwwTarget,  "http://" + wwwTargetUrl))
            .concat(cleanQueryTest("https", sourceHTTPS, httpTarget, httpTargetUrl))
            .concat(cleanQueryTest("wwws",  sourceHTTPS, wwwTarget,  "http://" + wwwTargetUrl))
            .concat(otherTests);
    for (var index = 0; index < tests.length; index++) {
        var [ testID, from, to ] = tests[index];
        assert.equal(
           url.getRedirectTarget(from),
           to,
           testID + ": Wrong redirection target for " + from
        );
    }
};

require("sdk/test").run(exports);<commit_msg>Add test for two redirect urls<commit_after>var url = require("./url");

var sourceHTTP = "http://www.some.website.com/";
var sourceHTTPS = "https://www.some.website.com/";

var queryAndFragment = "?some=parameter&some-other=parameter;a=parameter-with-?-in-it#some-fragment";

var httpTargetUrl = "http://redirection.target.com/";
var httpTargetClean = httpTargetUrl + queryAndFragment;
var httpTargetEncoded = encodeURIComponent(httpTargetClean);
var httpTargetDoubleEncoded = encodeURIComponent(httpTargetEncoded);

var httpTarget = {
    clean: httpTargetClean,
    encoded: httpTargetEncoded,
    doubleEncoded: httpTargetDoubleEncoded,
};

var wwwTargetUrl = "www.redirection.target.com/";
var wwwTargetClean = wwwTargetUrl + queryAndFragment;
var wwwTargetEncoded = encodeURIComponent(wwwTargetClean);
var wwwTargetDoubleEncoded = encodeURIComponent(wwwTargetEncoded);

var wwwTarget = {
    clean: wwwTargetClean,
    encoded: wwwTargetEncoded,
    doubleEncoded: wwwTargetDoubleEncoded,
};

var noRedirectUrls = [
    httpTargetClean,
    sourceHTTP + wwwTargetClean.replace("www.", "www"),
    sourceHTTP + "/login?continue=" + httpTargetClean + "#some-fragment",
    sourceHTTP + "/login?continue=" + httpTargetEncoded + "#some-fragment",
    sourceHTTP + "/login?continue=" + httpTargetDoubleEncoded + "#some-fragment]",
];
var noRedirectTests = [for (url of noRedirectUrls) ["no", url, url]];

function pathTest(id, source, target, expected) {
    return [
        ["pa01" + id, source + target.clean, expected],
        ["pa02" + id, source + target.encoded, expected],
        ["pa03" + id, source + target.doubleEncoded, expected],

        ["pa04" + id, source + "/?" + target.clean, expected],
        ["pa05" + id, source + "/?" + target.encoded, expected],
        ["pa06" + id, source + "/?" + target.doubleEncoded, expected],
    ];
}

function cleanQueryTest(id, source, target, expected) {
    return [
        ["cqu01" + id, source + "/?target=" + target.clean, expected],
        ["cqu02" + id, source + "/?target=" + target.clean + "&some=parameter", expected],
        ["cqu03" + id, source + "/?target=" + target.clean + ";some=parameter", expected],
        ["cqu04" + id, source + "/?target=" + target.clean + "#some-fragment", expected],
    ];
}

function queryTest(id, source, target, expected) {
    return [
        ["qu01" + id, source + "/?target=" + target.encoded, expected],
        ["qu02" + id, source + "/?target=" + target.encoded + "&some=parameter", expected],
        ["qu03" + id, source + "/?target=" + target.encoded + ";some=parameter", expected],
        ["qu04" + id, source + "/?target=" + target.encoded + "#some-fragment", expected],

        ["qu05" + id, source + "/?target=" + target.doubleEncoded, expected],
        ["qu06" + id, source + "/?target=" + target.doubleEncoded + "&some=parameter", expected],
        ["qu07" + id, source + "/?target=" + target.doubleEncoded + ";some=parameter", expected],
        ["qu08" + id, source + "/?target=" + target.doubleEncoded + "#some-fragment", expected],
    ];
}

var someOtherTargetUrl = "www.some.other.website.com";
var twoTargetsTests = [
    ["tt1", sourceHTTP + "?url-one=" + wwwTargetUrl + "&url-two=" + someOtherTargetUrl, "http://" + someOtherTargetUrl],
    ["tt1", sourceHTTP + "?url-one=" + httpTargetUrl + "&url-two=" + "http://" + someOtherTargetUrl, "http://" + someOtherTargetUrl],
];

exports["test redirects"] = function(assert) {
    var tests =
        []
            .concat(noRedirectTests)
            .concat(pathTest("http",        sourceHTTP,  httpTarget, httpTargetClean))
            .concat(pathTest("www",         sourceHTTP,  wwwTarget,  "http://" + wwwTargetClean))
            .concat(pathTest("https",       sourceHTTPS, httpTarget, httpTargetClean))
            .concat(pathTest("wwws",        sourceHTTPS, wwwTarget,  "http://" + wwwTargetClean))
            .concat(queryTest("http",       sourceHTTP,  httpTarget, httpTargetClean))
            .concat(queryTest("www",        sourceHTTP,  wwwTarget,  "http://" + wwwTargetClean))
            .concat(queryTest("https",      sourceHTTPS, httpTarget, httpTargetClean))
            .concat(queryTest("wwws",       sourceHTTPS, wwwTarget,  "http://" + wwwTargetClean))
            .concat(cleanQueryTest("http",  sourceHTTP,  httpTarget, httpTargetUrl))
            .concat(cleanQueryTest("www",   sourceHTTP,  wwwTarget,  "http://" + wwwTargetUrl))
            .concat(cleanQueryTest("https", sourceHTTPS, httpTarget, httpTargetUrl))
            .concat(cleanQueryTest("wwws",  sourceHTTPS, wwwTarget,  "http://" + wwwTargetUrl))
            .concat(twoTargetsTests)
            .concat([]);
    for (var index = 0; index < tests.length; index++) {
        var [ testID, from, to ] = tests[index];
        assert.equal(
           url.getRedirectTarget(from),
           to,
           testID + ": Wrong redirection target for " + from
        );
    }
};

require("sdk/test").run(exports);
{'fraction_non_alphanumeric': 0.1621960129422816, 'fraction_numerical': 0.007932366141321366, 'mean_word_length': 3.343608340888486, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 72, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3345064', 'n_tokens_mistral': 2896, 'n_tokens_neox': 2860, 'n_words': 615}