michael@0: /** michael@0: * Tests for parsing header fields using the syntax used in michael@0: * Content-Disposition and Content-Type michael@0: * michael@0: * See also https://bugzilla.mozilla.org/show_bug.cgi?id=609667 michael@0: */ michael@0: michael@0: var BS = '\\'; michael@0: var DQUOTE = '"'; michael@0: michael@0: // Test array: michael@0: // - element 0: "Content-Disposition" header to test michael@0: // under MIME (email): michael@0: // - element 1: correct value returned for disposition-type (empty param name) michael@0: // - element 2: correct value for filename returned michael@0: // under HTTP: michael@0: // (currently supports continuations; expected results without continuations michael@0: // are commented out for now) michael@0: // - element 3: correct value returned for disposition-type (empty param name) michael@0: // - element 4: correct value for filename returned michael@0: // michael@0: // 3 and 4 may be left out if they are identical michael@0: michael@0: var tests = [ michael@0: // No filename parameter: return nothing michael@0: ["attachment;", michael@0: "attachment", Cr.NS_ERROR_INVALID_ARG], michael@0: michael@0: // basic michael@0: ["attachment; filename=basic", michael@0: "attachment", "basic"], michael@0: michael@0: // extended michael@0: ["attachment; filename*=UTF-8''extended", michael@0: "attachment", "extended"], michael@0: michael@0: // prefer extended to basic (bug 588781) michael@0: ["attachment; filename=basic; filename*=UTF-8''extended", michael@0: "attachment", "extended"], michael@0: michael@0: // prefer extended to basic (bug 588781) michael@0: ["attachment; filename*=UTF-8''extended; filename=basic", michael@0: "attachment", "extended"], michael@0: michael@0: // use first basic value (invalid; error recovery) michael@0: ["attachment; filename=first; filename=wrong", michael@0: "attachment", "first"], michael@0: michael@0: // old school bad HTTP servers: missing 'attachment' or 'inline' michael@0: // (invalid; error recovery) michael@0: ["filename=old", michael@0: "filename=old", "old"], michael@0: michael@0: ["attachment; filename*=UTF-8''extended", michael@0: "attachment", "extended"], michael@0: michael@0: // continuations not part of RFC 5987 (bug 610054) michael@0: ["attachment; filename*0=foo; filename*1=bar", michael@0: "attachment", "foobar", michael@0: /* "attachment", Cr.NS_ERROR_INVALID_ARG */], michael@0: michael@0: // Return first continuation (invalid; error recovery) michael@0: ["attachment; filename*0=first; filename*0=wrong; filename=basic", michael@0: "attachment", "first", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // Only use correctly ordered continuations (invalid; error recovery) michael@0: ["attachment; filename*0=first; filename*1=second; filename*0=wrong", michael@0: "attachment", "firstsecond", michael@0: /* "attachment", Cr.NS_ERROR_INVALID_ARG */], michael@0: michael@0: // prefer continuation to basic (unless RFC 5987) michael@0: ["attachment; filename=basic; filename*0=foo; filename*1=bar", michael@0: "attachment", "foobar", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // Prefer extended to basic and/or (broken or not) continuation michael@0: // (invalid; error recovery) michael@0: ["attachment; filename=basic; filename*0=first; filename*0=wrong; filename*=UTF-8''extended", michael@0: "attachment", "extended"], michael@0: michael@0: // RFC 2231 not clear on correct outcome: we prefer non-continued extended michael@0: // (invalid; error recovery) michael@0: ["attachment; filename=basic; filename*=UTF-8''extended; filename*0=foo; filename*1=bar", michael@0: "attachment", "extended"], michael@0: michael@0: // Gaps should result in returning only value until gap hit michael@0: // (invalid; error recovery) michael@0: ["attachment; filename*0=foo; filename*2=bar", michael@0: "attachment", "foo", michael@0: /* "attachment", Cr.NS_ERROR_INVALID_ARG */], michael@0: michael@0: // Don't allow leading 0's (*01) (invalid; error recovery) michael@0: ["attachment; filename*0=foo; filename*01=bar", michael@0: "attachment", "foo", michael@0: /* "attachment", Cr.NS_ERROR_INVALID_ARG */], michael@0: michael@0: // continuations should prevail over non-extended (unless RFC 5987) michael@0: ["attachment; filename=basic; filename*0*=UTF-8''multi;\r\n" michael@0: + " filename*1=line;\r\n" michael@0: + " filename*2*=%20extended", michael@0: "attachment", "multiline extended", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // Gaps should result in returning only value until gap hit michael@0: // (invalid; error recovery) michael@0: ["attachment; filename=basic; filename*0*=UTF-8''multi;\r\n" michael@0: + " filename*1=line;\r\n" michael@0: + " filename*3*=%20extended", michael@0: "attachment", "multiline", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // First series, only please, and don't slurp up higher elements (*2 in this michael@0: // case) from later series into earlier one (invalid; error recovery) michael@0: ["attachment; filename=basic; filename*0*=UTF-8''multi;\r\n" michael@0: + " filename*1=line;\r\n" michael@0: + " filename*0*=UTF-8''wrong;\r\n" michael@0: + " filename*1=bad;\r\n" michael@0: + " filename*2=evil", michael@0: "attachment", "multiline", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // RFC 2231 not clear on correct outcome: we prefer non-continued extended michael@0: // (invalid; error recovery) michael@0: ["attachment; filename=basic; filename*0=UTF-8''multi\r\n;" michael@0: + " filename*=UTF-8''extended;\r\n" michael@0: + " filename*1=line;\r\n" michael@0: + " filename*2*=%20extended", michael@0: "attachment", "extended"], michael@0: michael@0: // sneaky: if unescaped, make sure we leave UTF-8'' in value michael@0: ["attachment; filename*0=UTF-8''unescaped;\r\n" michael@0: + " filename*1*=%20so%20includes%20UTF-8''%20in%20value", michael@0: "attachment", "UTF-8''unescaped so includes UTF-8'' in value", michael@0: /* "attachment", Cr.NS_ERROR_INVALID_ARG */], michael@0: michael@0: // sneaky: if unescaped, make sure we leave UTF-8'' in value michael@0: ["attachment; filename=basic; filename*0=UTF-8''unescaped;\r\n" michael@0: + " filename*1*=%20so%20includes%20UTF-8''%20in%20value", michael@0: "attachment", "UTF-8''unescaped so includes UTF-8'' in value", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // Prefer basic over invalid continuation michael@0: // (invalid; error recovery) michael@0: ["attachment; filename=basic; filename*1=multi;\r\n" michael@0: + " filename*2=line;\r\n" michael@0: + " filename*3*=%20extended", michael@0: "attachment", "basic"], michael@0: michael@0: // support digits over 10 michael@0: ["attachment; filename=basic; filename*0*=UTF-8''0;\r\n" michael@0: + " filename*1=1; filename*2=2;filename*3=3;filename*4=4;filename*5=5;\r\n" michael@0: + " filename*6=6; filename*7=7;filename*8=8;filename*9=9;filename*10=a;\r\n" michael@0: + " filename*11=b; filename*12=c;filename*13=d;filename*14=e;filename*15=f\r\n", michael@0: "attachment", "0123456789abcdef", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // support digits over 10 (detect gaps) michael@0: ["attachment; filename=basic; filename*0*=UTF-8''0;\r\n" michael@0: + " filename*1=1; filename*2=2;filename*3=3;filename*4=4;filename*5=5;\r\n" michael@0: + " filename*6=6; filename*7=7;filename*8=8;filename*9=9;filename*10=a;\r\n" michael@0: + " filename*11=b; filename*12=c;filename*14=e\r\n", michael@0: "attachment", "0123456789abc", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // return nothing: invalid michael@0: // (invalid; error recovery) michael@0: ["attachment; filename*1=multi;\r\n" michael@0: + " filename*2=line;\r\n" michael@0: + " filename*3*=%20extended", michael@0: "attachment", Cr.NS_ERROR_INVALID_ARG], michael@0: michael@0: // Bug 272541: Empty disposition type treated as "attachment" michael@0: michael@0: // sanity check michael@0: ["attachment; filename=foo.html", michael@0: "attachment", "foo.html", michael@0: "attachment", "foo.html"], michael@0: michael@0: // the actual bug michael@0: ["; filename=foo.html", michael@0: Cr.NS_ERROR_FIRST_HEADER_FIELD_COMPONENT_EMPTY, "foo.html", michael@0: Cr.NS_ERROR_FIRST_HEADER_FIELD_COMPONENT_EMPTY, "foo.html"], michael@0: michael@0: // regression check, but see bug 671204 michael@0: ["filename=foo.html", michael@0: "filename=foo.html", "foo.html", michael@0: "filename=foo.html", "foo.html"], michael@0: michael@0: // Bug 384571: RFC 2231 parameters not decoded when appearing in reversed order michael@0: michael@0: // check ordering michael@0: ["attachment; filename=basic; filename*0*=UTF-8''0;\r\n" michael@0: + " filename*1=1; filename*2=2;filename*3=3;filename*4=4;filename*5=5;\r\n" michael@0: + " filename*6=6; filename*7=7;filename*8=8;filename*9=9;filename*10=a;\r\n" michael@0: + " filename*11=b; filename*12=c;filename*13=d;filename*15=f;filename*14=e;\r\n", michael@0: "attachment", "0123456789abcdef", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // check non-digits in sequence numbers michael@0: ["attachment; filename=basic; filename*0*=UTF-8''0;\r\n" michael@0: + " filename*1a=1\r\n", michael@0: "attachment", "0", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // check duplicate sequence numbers michael@0: ["attachment; filename=basic; filename*0*=UTF-8''0;\r\n" michael@0: + " filename*0=bad; filename*1=1;\r\n", michael@0: "attachment", "0", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // check overflow michael@0: ["attachment; filename=basic; filename*0*=UTF-8''0;\r\n" michael@0: + " filename*11111111111111111111111111111111111111111111111111111111111=1", michael@0: "attachment", "0", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // check underflow michael@0: ["attachment; filename=basic; filename*0*=UTF-8''0;\r\n" michael@0: + " filename*-1=1", michael@0: "attachment", "0", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // check mixed token/quoted-string michael@0: ["attachment; filename=basic; filename*0=\"0\";\r\n" michael@0: + " filename*1=1;\r\n" michael@0: + " filename*2*=%32", michael@0: "attachment", "012", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // check empty sequence number michael@0: ["attachment; filename=basic; filename**=UTF-8''0\r\n", michael@0: "attachment", "basic", michael@0: "attachment", "basic"], michael@0: michael@0: michael@0: // Bug 419157: ensure that a MIME parameter with no charset information michael@0: // fallbacks to Latin-1 michael@0: michael@0: ["attachment;filename=IT839\x04\xB5(m8)2.pdf;", michael@0: "attachment", "IT839\u0004\u00b5(m8)2.pdf"], michael@0: michael@0: // Bug 588389: unescaping backslashes in quoted string parameters michael@0: michael@0: // '\"', should be parsed as '"' michael@0: ["attachment; filename=" + DQUOTE + (BS + DQUOTE) + DQUOTE, michael@0: "attachment", DQUOTE], michael@0: michael@0: // 'a\"b', should be parsed as 'a"b' michael@0: ["attachment; filename=" + DQUOTE + 'a' + (BS + DQUOTE) + 'b' + DQUOTE, michael@0: "attachment", "a" + DQUOTE + "b"], michael@0: michael@0: // '\x', should be parsed as 'x' michael@0: ["attachment; filename=" + DQUOTE + (BS + "x") + DQUOTE, michael@0: "attachment", "x"], michael@0: michael@0: // test empty param (quoted-string) michael@0: ["attachment; filename=" + DQUOTE + DQUOTE, michael@0: "attachment", ""], michael@0: michael@0: // test empty param michael@0: ["attachment; filename=", michael@0: "attachment", ""], michael@0: michael@0: // Bug 601933: RFC 2047 does not apply to parameters (at least in HTTP) michael@0: ["attachment; filename==?ISO-8859-1?Q?foo-=E4.html?=", michael@0: "attachment", "foo-\u00e4.html", michael@0: /* "attachment", "=?ISO-8859-1?Q?foo-=E4.html?=" */], michael@0: michael@0: ["attachment; filename=\"=?ISO-8859-1?Q?foo-=E4.html?=\"", michael@0: "attachment", "foo-\u00e4.html", michael@0: /* "attachment", "=?ISO-8859-1?Q?foo-=E4.html?=" */], michael@0: michael@0: // format sent by GMail as of 2012-07-23 (5987 overrides 2047) michael@0: ["attachment; filename=\"=?ISO-8859-1?Q?foo-=E4.html?=\"; filename*=UTF-8''5987", michael@0: "attachment", "5987"], michael@0: michael@0: // Bug 651185: double quotes around 2231/5987 encoded param michael@0: // Change reverted to backwards compat issues with various web services, michael@0: // such as OWA (Bug 703015), plus similar problems in Thunderbird. If this michael@0: // is tried again in the future, email probably needs to be special-cased. michael@0: michael@0: // sanity check michael@0: ["attachment; filename*=utf-8''%41", michael@0: "attachment", "A"], michael@0: michael@0: // the actual bug michael@0: ["attachment; filename*=" + DQUOTE + "utf-8''%41" + DQUOTE, michael@0: "attachment", "A"], michael@0: // previously with the fix for 651185: michael@0: // "attachment", Cr.NS_ERROR_INVALID_ARG], michael@0: michael@0: // Bug 670333: Content-Disposition parser does not require presence of "=" michael@0: // in params michael@0: michael@0: // sanity check michael@0: ["attachment; filename*=UTF-8''foo-%41.html", michael@0: "attachment", "foo-A.html"], michael@0: michael@0: // the actual bug michael@0: ["attachment; filename *=UTF-8''foo-%41.html", michael@0: "attachment", Cr.NS_ERROR_INVALID_ARG], michael@0: michael@0: // the actual bug, without 2231/5987 encoding michael@0: ["attachment; filename X", michael@0: "attachment", Cr.NS_ERROR_INVALID_ARG], michael@0: michael@0: // sanity check with WS on both sides michael@0: ["attachment; filename = foo-A.html", michael@0: "attachment", "foo-A.html"], michael@0: michael@0: // Bug 685192: in RFC2231/5987 encoding, a missing charset field should be michael@0: // treated as error michael@0: michael@0: // the actual bug michael@0: ["attachment; filename*=''foo", michael@0: "attachment", "foo"], michael@0: // previously with the fix for 692574: michael@0: // "attachment", Cr.NS_ERROR_INVALID_ARG], michael@0: michael@0: // sanity check michael@0: ["attachment; filename*=a''foo", michael@0: "attachment", "foo"], michael@0: michael@0: // Bug 692574: RFC2231/5987 decoding should not tolerate missing single michael@0: // quotes michael@0: michael@0: // one missing michael@0: ["attachment; filename*=UTF-8'foo-%41.html", michael@0: "attachment", "foo-A.html"], michael@0: // previously with the fix for 692574: michael@0: // "attachment", Cr.NS_ERROR_INVALID_ARG], michael@0: michael@0: // both missing michael@0: ["attachment; filename*=foo-%41.html", michael@0: "attachment","foo-A.html"], michael@0: // previously with the fix for 692574: michael@0: // "attachment", Cr.NS_ERROR_INVALID_ARG], michael@0: michael@0: // make sure fallback works michael@0: ["attachment; filename*=UTF-8'foo-%41.html; filename=bar.html", michael@0: "attachment", "foo-A.html"], michael@0: // previously with the fix for 692574: michael@0: // "attachment", "bar.html"], michael@0: michael@0: // Bug 693806: RFC2231/5987 encoding: charset information should be treated michael@0: // as authoritative michael@0: michael@0: // UTF-8 labeled ISO-8859-1 michael@0: ["attachment; filename*=ISO-8859-1''%c3%a4", michael@0: "attachment", "\u00c3\u00a4"], michael@0: michael@0: // UTF-8 labeled ISO-8859-1, but with octets not allowed in ISO-8859-1 michael@0: // accepts x82, understands it as Win1252, maps it to Unicode \u20a1 michael@0: ["attachment; filename*=ISO-8859-1''%e2%82%ac", michael@0: "attachment", "\u00e2\u201a\u00ac"], michael@0: michael@0: // defective UTF-8 michael@0: ["attachment; filename*=UTF-8''A%e4B", michael@0: "attachment", Cr.NS_ERROR_INVALID_ARG], michael@0: michael@0: // defective UTF-8, with fallback michael@0: ["attachment; filename*=UTF-8''A%e4B; filename=fallback", michael@0: "attachment", "fallback"], michael@0: michael@0: // defective UTF-8 (continuations), with fallback michael@0: ["attachment; filename*0*=UTF-8''A%e4B; filename=fallback", michael@0: "attachment", "fallback"], michael@0: michael@0: // check that charsets aren't mixed up michael@0: ["attachment; filename*0*=ISO-8859-15''euro-sign%3d%a4; filename*=ISO-8859-1''currency-sign%3d%a4", michael@0: "attachment", "currency-sign=\u00a4"], michael@0: michael@0: // same as above, except reversed michael@0: ["attachment; filename*=ISO-8859-1''currency-sign%3d%a4; filename*0*=ISO-8859-15''euro-sign%3d%a4", michael@0: "attachment", "currency-sign=\u00a4"], michael@0: michael@0: // Bug 704989: add workaround for broken Outlook Web App (OWA) michael@0: // attachment handling michael@0: michael@0: ["attachment; filename*=\"a%20b\"", michael@0: "attachment", "a b"], michael@0: michael@0: // Bug 717121: crash nsMIMEHeaderParamImpl::DoParameterInternal michael@0: michael@0: ["attachment; filename=\"", michael@0: "attachment", ""], michael@0: michael@0: // We used to read past string if last param w/o = and ; michael@0: // Note: was only detected on windows PGO builds michael@0: ["attachment; filename=foo; trouble", michael@0: "attachment", "foo"], michael@0: michael@0: // Same, followed by space, hits another case michael@0: ["attachment; filename=foo; trouble ", michael@0: "attachment", "foo"], michael@0: michael@0: ["attachment", michael@0: "attachment", Cr.NS_ERROR_INVALID_ARG], michael@0: michael@0: // Bug 730574: quoted-string in RFC2231-continuations not handled michael@0: michael@0: ['attachment; filename=basic; filename*0="foo"; filename*1="\\b\\a\\r.html"', michael@0: "attachment", "foobar.html", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // unmatched escape char michael@0: ['attachment; filename=basic; filename*0="foo"; filename*1="\\b\\a\\', michael@0: "attachment", "fooba\\", michael@0: /* "attachment", "basic" */], michael@0: michael@0: // Bug 732369: Content-Disposition parser does not require presence of ";" between params michael@0: // optimally, this would not even return the disposition type "attachment" michael@0: michael@0: ["attachment; extension=bla filename=foo", michael@0: "attachment", Cr.NS_ERROR_INVALID_ARG], michael@0: michael@0: ["attachment; filename=foo extension=bla", michael@0: "attachment", "foo"], michael@0: michael@0: ["attachment filename=foo", michael@0: "attachment", Cr.NS_ERROR_INVALID_ARG], michael@0: michael@0: // Bug 777687: handling of broken %escapes michael@0: michael@0: ["attachment; filename*=UTF-8''f%oo; filename=bar", michael@0: "attachment", "bar"], michael@0: michael@0: ["attachment; filename*=UTF-8''foo%; filename=bar", michael@0: "attachment", "bar"], michael@0: michael@0: // Bug 783502 - xpcshell test netwerk/test/unit/test_MIME_params.js fails on AddressSanitizer michael@0: ['attachment; filename="\\b\\a\\', michael@0: "attachment", "ba\\"], michael@0: ]; michael@0: michael@0: var rfc5987paramtests = [ michael@0: [ // basic test michael@0: "UTF-8'language'value", "value", "language", Cr.NS_OK ], michael@0: [ // percent decoding michael@0: "UTF-8''1%202", "1 2", "", Cr.NS_OK ], michael@0: [ // UTF-8 michael@0: "UTF-8''%c2%a3%20and%20%e2%82%ac%20rates", "\u00a3 and \u20ac rates", "", Cr.NS_OK ], michael@0: [ // missing charset michael@0: "''abc", "", "", Cr.NS_ERROR_INVALID_ARG ], michael@0: [ // ISO-8859-1: unsupported michael@0: "ISO-8859-1''%A3%20rates", "", "", Cr.NS_ERROR_INVALID_ARG ], michael@0: [ // unknown charset michael@0: "foo''abc", "", "", Cr.NS_ERROR_INVALID_ARG ], michael@0: [ // missing component michael@0: "abc", "", "", Cr.NS_ERROR_INVALID_ARG ], michael@0: [ // missing component michael@0: "'abc", "", "", Cr.NS_ERROR_INVALID_ARG ], michael@0: [ // illegal chars michael@0: "UTF-8''a b", "", "", Cr.NS_ERROR_INVALID_ARG ], michael@0: [ // broken % escapes michael@0: "UTF-8''a%zz", "", "", Cr.NS_ERROR_INVALID_ARG ], michael@0: [ // broken % escapes michael@0: "UTF-8''a%b", "", "", Cr.NS_ERROR_INVALID_ARG ], michael@0: [ // broken % escapes michael@0: "UTF-8''a%", "", "", Cr.NS_ERROR_INVALID_ARG ], michael@0: [ // broken UTF-8 michael@0: "UTF-8''%A3%20rates", "", "", 0x8050000E /* NS_ERROR_UDEC_ILLEGALINPUT */ ], michael@0: ]; michael@0: michael@0: function do_tests(whichRFC) michael@0: { michael@0: var mhp = Components.classes["@mozilla.org/network/mime-hdrparam;1"] michael@0: .getService(Components.interfaces.nsIMIMEHeaderParam); michael@0: michael@0: var unused = { value : null }; michael@0: michael@0: for (var i = 0; i < tests.length; ++i) { michael@0: dump("Testing #" + i + ": " + tests[i] + "\n"); michael@0: michael@0: // check disposition type michael@0: var expectedDt = tests[i].length == 3 || whichRFC == 0 ? tests[i][1] : tests[i][3]; michael@0: michael@0: try { michael@0: var result; michael@0: michael@0: if (whichRFC == 0) michael@0: result = mhp.getParameter(tests[i][0], "", "UTF-8", true, unused); michael@0: else michael@0: result = mhp.getParameterHTTP(tests[i][0], "", "UTF-8", true, unused); michael@0: michael@0: do_check_eq(result, expectedDt); michael@0: } michael@0: catch (e) { michael@0: // Tests can also succeed by expecting to fail with given error code michael@0: if (e.result) { michael@0: // Allow following tests to run by catching exception from do_check_eq() michael@0: try { michael@0: do_check_eq(e.result, expectedDt); michael@0: } catch(e) {} michael@0: } michael@0: continue; michael@0: } michael@0: michael@0: // check filename parameter michael@0: var expectedFn = tests[i].length == 3 || whichRFC == 0 ? tests[i][2] : tests[i][4]; michael@0: michael@0: try { michael@0: var result; michael@0: michael@0: if (whichRFC == 0) michael@0: result = mhp.getParameter(tests[i][0], "filename", "UTF-8", true, unused); michael@0: else michael@0: result = mhp.getParameterHTTP(tests[i][0], "filename", "UTF-8", true, unused); michael@0: michael@0: do_check_eq(result, expectedFn); michael@0: } michael@0: catch (e) { michael@0: // Tests can also succeed by expecting to fail with given error code michael@0: if (e.result) { michael@0: // Allow following tests to run by catching exception from do_check_eq() michael@0: try { michael@0: do_check_eq(e.result, expectedFn); michael@0: } catch(e) {} michael@0: } michael@0: continue; michael@0: } michael@0: } michael@0: } michael@0: michael@0: function test_decode5987Param() { michael@0: var mhp = Components.classes["@mozilla.org/network/mime-hdrparam;1"] michael@0: .getService(Components.interfaces.nsIMIMEHeaderParam); michael@0: michael@0: for (var i = 0; i < rfc5987paramtests.length; ++i) { michael@0: dump("Testing #" + i + ": " + rfc5987paramtests[i] + "\n"); michael@0: michael@0: var lang = {}; michael@0: try { michael@0: var decoded = mhp.decodeRFC5987Param(rfc5987paramtests[i][0], lang); michael@0: if (rfc5987paramtests[i][3] == Cr.NS_OK) { michael@0: do_check_eq(rfc5987paramtests[i][1], decoded); michael@0: do_check_eq(rfc5987paramtests[i][2], lang.value); michael@0: } michael@0: else { michael@0: do_check_eq(rfc5987paramtests[i][3], "instead got: " + decoded); michael@0: } michael@0: } michael@0: catch (e) { michael@0: do_check_eq(rfc5987paramtests[i][3], e.result); michael@0: } michael@0: } michael@0: } michael@0: michael@0: function run_test() { michael@0: michael@0: // Test RFC 2231 (complete header field values) michael@0: do_tests(0); michael@0: michael@0: // Test RFC 5987 (complete header field values) michael@0: do_tests(1); michael@0: michael@0: // tests for RFC5987 parameter parsing michael@0: test_decode5987Param(); michael@0: }