// Test array: // - element 0: "Content-Disposition" header to test // under MIME (email): // - element 1: correct value returned for disposition-type (empty param name) // - element 2: correct value for filename returned // under HTTP: // (currently supports continuations; expected results without continuations // are commented out for now) // - element 3: correct value returned for disposition-type (empty param name) // - element 4: correct value for filename returned // // 3 and 4 may be left out if they are identical
var tests = [ // No filename parameter: return nothing
["attachment;", "attachment", Cr.NS_ERROR_INVALID_ARG],
// RFC 2231 not clear on correct outcome: we prefer non-continued extended // (invalid; error recovery)
[ "attachment; filename=basic; filename*=UTF-8''extended; filename*0=foo; filename*1=bar", "attachment", "extended",
],
// Gaps should result in returning only value until gap hit // (invalid; error recovery)
[ "attachment; filename*0=foo; filename*2=bar", "attachment", "foo", /* "attachment", Cr.NS_ERROR_INVALID_ARG */
],
// Gaps should result in returning only value until gap hit // (invalid; error recovery)
[ "attachment; filename=basic; filename*0*=UTF-8''multi;\r\n" + " filename*1=line;\r\n" + " filename*3*=%20extended", "attachment", "multiline", /* "attachment", "basic" */
],
// First series, only please, and don't slurp up higher elements (*2 in this // case) from later series into earlier one (invalid; error recovery)
[ "attachment; filename=basic; filename*0*=UTF-8''multi;\r\n" + " filename*1=line;\r\n" + " filename*0*=UTF-8''wrong;\r\n" + " filename*1=bad;\r\n" + " filename*2=evil", "attachment", "multiline", /* "attachment", "basic" */
],
// sneaky: if unescaped, make sure we leave UTF-8'' in value
[ "attachment; filename*0=UTF-8''unescaped;\r\n" + " filename*1*=%20so%20includes%20UTF-8''%20in%20value", "attachment", "UTF-8''unescaped so includes UTF-8'' in value", /* "attachment", Cr.NS_ERROR_INVALID_ARG */
],
// sneaky: if unescaped, make sure we leave UTF-8'' in value
[ "attachment; filename=basic; filename*0=UTF-8''unescaped;\r\n" + " filename*1*=%20so%20includes%20UTF-8''%20in%20value", "attachment", "UTF-8''unescaped so includes UTF-8'' in value", /* "attachment", "basic" */
],
// test empty param
["attachment; filename=", "attachment", ""],
// Bug 601933: RFC 2047 does not apply to parameters (at least in HTTP)
[ "attachment; filename==?ISO-8859-1?Q?foo-=E4.html?=", "attachment", "foo-\u00e4.html", /* "attachment", "=?ISO-8859-1?Q?foo-=E4.html?=" */
],
// format sent by GMail as of 2012-07-23 (5987 overrides 2047)
[ "attachment; filename=\"=?ISO-8859-1?Q?foo-=E4.html?=\"; filename*=UTF-8''5987", "attachment", "5987",
],
// Bug 651185: double quotes around 2231/5987 encoded param // Change reverted to backwards compat issues with various web services, // such as OWA (Bug 703015), plus similar problems in Thunderbird. If this // is tried again in the future, email probably needs to be special-cased.
// the actual bug
[ "attachment; filename *=UTF-8''foo-%41.html", "attachment",
Cr.NS_ERROR_INVALID_ARG,
],
// the actual bug, without 2231/5987 encoding
["attachment; filename X", "attachment", Cr.NS_ERROR_INVALID_ARG],
// sanity check with WS on both sides
["attachment; filename = foo-A.html", "attachment", "foo-A.html"],
// Bug 685192: in RFC2231/5987 encoding, a missing charset field should be // treated as error
// the actual bug
["attachment; filename*=''foo", "attachment", "foo"], // previously with the fix for 692574: // "attachment", Cr.NS_ERROR_INVALID_ARG],
// Bug 692574: RFC2231/5987 decoding should not tolerate missing single // quotes
// one missing
["attachment; filename*=UTF-8'foo-%41.html", "attachment", "foo-A.html"], // previously with the fix for 692574: // "attachment", Cr.NS_ERROR_INVALID_ARG],
// both missing
["attachment; filename*=foo-%41.html", "attachment", "foo-A.html"], // previously with the fix for 692574: // "attachment", Cr.NS_ERROR_INVALID_ARG],
// make sure fallback works
[ "attachment; filename*=UTF-8'foo-%41.html; filename=bar.html", "attachment", "foo-A.html",
], // previously with the fix for 692574: // "attachment", "bar.html"],
// Bug 693806: RFC2231/5987 encoding: charset information should be treated // as authoritative
// UTF-8 labeled ISO-8859-1, but with octets not allowed in ISO-8859-1 // accepts x82, understands it as Win1252, maps it to Unicode \u20a1
[ "attachment; filename*=ISO-8859-1''%e2%82%ac", "attachment", "\u00e2\u201a\u00ac",
],
// We used to read past string if last param w/o = and ; // Note: was only detected on windows PGO builds
["attachment; filename=foo; trouble", "attachment", "foo"],
// Same, followed by space, hits another case
["attachment; filename=foo; trouble ", "attachment", "foo"],
// Bug 732369: Content-Disposition parser does not require presence of ";" between params // optimally, this would not even return the disposition type "attachment"
// Bug 1440677 - spaces inside filenames ought to be quoted, but too many // servers do the wrong thing and most browsers accept this, so we were // forced to do the same for compat.
["attachment; filename=foo extension=bla", "attachment", "foo extension=bla"],
// Bug 783502 - xpcshell test netwerk/test/unit/test_MIME_params.js fails on AddressSanitizer
['attachment; filename="\\b\\a\\', "attachment", "ba\\"],
// Bug 1412213 - do continue to parse, behind an empty parameter
["attachment; ; filename=foo", "attachment", "foo"],
// Bug 1412213 - do continue to parse, behind a parameter w/o =
["attachment; badparameter; filename=foo", "attachment", "foo"],
// Bug 1440677 - spaces inside filenames ought to be quoted, but too many // servers do the wrong thing and most browsers accept this, so we were // forced to do the same for compat.
["attachment; filename=foo bar.html", "attachment", "foo bar.html"], // Note: we keep the tab character, but later validation will replace with a space, // as file systems do not like tab characters.
["attachment; filename=foo\tbar.html", "attachment", "foo\tbar.html"], // Newlines get stripped completely (in practice, http header parsing may // munge these into spaces before they get to us, but we should check we deal // with them either way):
["attachment; filename=foo\nbar.html", "attachment", "foobar.html"],
["attachment; filename=foo\r\nbar.html", "attachment", "foobar.html"],
["attachment; filename=foo\rbar.html", "attachment", "foobar.html"],
function do_tests(whichRFC) { var mhp = Cc["@mozilla.org/network/mime-hdrparam;1"].getService(
Ci.nsIMIMEHeaderParam
);
var unused = { value: null };
for (var i = 0; i < tests.length; ++i) {
dump("Testing #" + i + ": " + tests[i] + "\n");
// check disposition type var expectedDt =
tests[i].length == 3 || whichRFC == 0 ? tests[i][1] : tests[i][3];
try {
let result;
if (whichRFC == 0) {
result = mhp.getParameter(tests[i][0], "", "UTF-8", true, unused);
} else {
result = mhp.getParameterHTTP(tests[i][0], "", "UTF-8", true, unused);
}
Assert.equal(result, expectedDt);
} catch (e) { // Tests can also succeed by expecting to fail with given error code if (e.result) { // Allow following tests to run by catching exception from do_check_eq() try { Assert.equal(e.result, expectedDt);
} catch (e1) {}
} continue;
}
if (whichRFC == 0) {
result = mhp.getParameter(
tests[i][0], "filename", "UTF-8", true,
unused
);
} else {
result = mhp.getParameterHTTP(
tests[i][0], "filename", "UTF-8", true,
unused
);
}
Assert.equal(result, expectedFn);
} catch (e) { // Tests can also succeed by expecting to fail with given error code if (e.result) { // Allow following tests to run by catching exception from do_check_eq() try { Assert.equal(e.result, expectedFn);
} catch (e1) {}
} continue;
}
}
}
function test_decode5987Param() { var mhp = Cc["@mozilla.org/network/mime-hdrparam;1"].getService(
Ci.nsIMIMEHeaderParam
);
for (var i = 0; i < rfc5987paramtests.length; ++i) {
dump("Testing #" + i + ": " + rfc5987paramtests[i] + "\n");
var lang = {}; try { var decoded = mhp.decodeRFC5987Param(rfc5987paramtests[i][0], lang); if (rfc5987paramtests[i][3] == Cr.NS_OK) { Assert.equal(rfc5987paramtests[i][1], decoded); Assert.equal(rfc5987paramtests[i][2], lang.value);
} else { Assert.equal(rfc5987paramtests[i][3], "instead got: " + decoded);
}
} catch (e) { Assert.equal(rfc5987paramtests[i][3], e.result);
}
}
}
function run_test() { // Test RFC 2231 (complete header field values)
do_tests(0);
// Test RFC 5987 (complete header field values)
do_tests(1);
// tests for RFC5987 parameter parsing
test_decode5987Param();
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.45 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.