Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /** |
michael@0 | 2 | * Tests for parsing header fields using the syntax used in |
michael@0 | 3 | * Content-Disposition and Content-Type |
michael@0 | 4 | * |
michael@0 | 5 | * See also https://bugzilla.mozilla.org/show_bug.cgi?id=609667 |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | var BS = '\\'; |
michael@0 | 9 | var DQUOTE = '"'; |
michael@0 | 10 | |
michael@0 | 11 | // Test array: |
michael@0 | 12 | // - element 0: "Content-Disposition" header to test |
michael@0 | 13 | // under MIME (email): |
michael@0 | 14 | // - element 1: correct value returned for disposition-type (empty param name) |
michael@0 | 15 | // - element 2: correct value for filename returned |
michael@0 | 16 | // under HTTP: |
michael@0 | 17 | // (currently supports continuations; expected results without continuations |
michael@0 | 18 | // are commented out for now) |
michael@0 | 19 | // - element 3: correct value returned for disposition-type (empty param name) |
michael@0 | 20 | // - element 4: correct value for filename returned |
michael@0 | 21 | // |
michael@0 | 22 | // 3 and 4 may be left out if they are identical |
michael@0 | 23 | |
michael@0 | 24 | var tests = [ |
michael@0 | 25 | // No filename parameter: return nothing |
michael@0 | 26 | ["attachment;", |
michael@0 | 27 | "attachment", Cr.NS_ERROR_INVALID_ARG], |
michael@0 | 28 | |
michael@0 | 29 | // basic |
michael@0 | 30 | ["attachment; filename=basic", |
michael@0 | 31 | "attachment", "basic"], |
michael@0 | 32 | |
michael@0 | 33 | // extended |
michael@0 | 34 | ["attachment; filename*=UTF-8''extended", |
michael@0 | 35 | "attachment", "extended"], |
michael@0 | 36 | |
michael@0 | 37 | // prefer extended to basic (bug 588781) |
michael@0 | 38 | ["attachment; filename=basic; filename*=UTF-8''extended", |
michael@0 | 39 | "attachment", "extended"], |
michael@0 | 40 | |
michael@0 | 41 | // prefer extended to basic (bug 588781) |
michael@0 | 42 | ["attachment; filename*=UTF-8''extended; filename=basic", |
michael@0 | 43 | "attachment", "extended"], |
michael@0 | 44 | |
michael@0 | 45 | // use first basic value (invalid; error recovery) |
michael@0 | 46 | ["attachment; filename=first; filename=wrong", |
michael@0 | 47 | "attachment", "first"], |
michael@0 | 48 | |
michael@0 | 49 | // old school bad HTTP servers: missing 'attachment' or 'inline' |
michael@0 | 50 | // (invalid; error recovery) |
michael@0 | 51 | ["filename=old", |
michael@0 | 52 | "filename=old", "old"], |
michael@0 | 53 | |
michael@0 | 54 | ["attachment; filename*=UTF-8''extended", |
michael@0 | 55 | "attachment", "extended"], |
michael@0 | 56 | |
michael@0 | 57 | // continuations not part of RFC 5987 (bug 610054) |
michael@0 | 58 | ["attachment; filename*0=foo; filename*1=bar", |
michael@0 | 59 | "attachment", "foobar", |
michael@0 | 60 | /* "attachment", Cr.NS_ERROR_INVALID_ARG */], |
michael@0 | 61 | |
michael@0 | 62 | // Return first continuation (invalid; error recovery) |
michael@0 | 63 | ["attachment; filename*0=first; filename*0=wrong; filename=basic", |
michael@0 | 64 | "attachment", "first", |
michael@0 | 65 | /* "attachment", "basic" */], |
michael@0 | 66 | |
michael@0 | 67 | // Only use correctly ordered continuations (invalid; error recovery) |
michael@0 | 68 | ["attachment; filename*0=first; filename*1=second; filename*0=wrong", |
michael@0 | 69 | "attachment", "firstsecond", |
michael@0 | 70 | /* "attachment", Cr.NS_ERROR_INVALID_ARG */], |
michael@0 | 71 | |
michael@0 | 72 | // prefer continuation to basic (unless RFC 5987) |
michael@0 | 73 | ["attachment; filename=basic; filename*0=foo; filename*1=bar", |
michael@0 | 74 | "attachment", "foobar", |
michael@0 | 75 | /* "attachment", "basic" */], |
michael@0 | 76 | |
michael@0 | 77 | // Prefer extended to basic and/or (broken or not) continuation |
michael@0 | 78 | // (invalid; error recovery) |
michael@0 | 79 | ["attachment; filename=basic; filename*0=first; filename*0=wrong; filename*=UTF-8''extended", |
michael@0 | 80 | "attachment", "extended"], |
michael@0 | 81 | |
michael@0 | 82 | // RFC 2231 not clear on correct outcome: we prefer non-continued extended |
michael@0 | 83 | // (invalid; error recovery) |
michael@0 | 84 | ["attachment; filename=basic; filename*=UTF-8''extended; filename*0=foo; filename*1=bar", |
michael@0 | 85 | "attachment", "extended"], |
michael@0 | 86 | |
michael@0 | 87 | // Gaps should result in returning only value until gap hit |
michael@0 | 88 | // (invalid; error recovery) |
michael@0 | 89 | ["attachment; filename*0=foo; filename*2=bar", |
michael@0 | 90 | "attachment", "foo", |
michael@0 | 91 | /* "attachment", Cr.NS_ERROR_INVALID_ARG */], |
michael@0 | 92 | |
michael@0 | 93 | // Don't allow leading 0's (*01) (invalid; error recovery) |
michael@0 | 94 | ["attachment; filename*0=foo; filename*01=bar", |
michael@0 | 95 | "attachment", "foo", |
michael@0 | 96 | /* "attachment", Cr.NS_ERROR_INVALID_ARG */], |
michael@0 | 97 | |
michael@0 | 98 | // continuations should prevail over non-extended (unless RFC 5987) |
michael@0 | 99 | ["attachment; filename=basic; filename*0*=UTF-8''multi;\r\n" |
michael@0 | 100 | + " filename*1=line;\r\n" |
michael@0 | 101 | + " filename*2*=%20extended", |
michael@0 | 102 | "attachment", "multiline extended", |
michael@0 | 103 | /* "attachment", "basic" */], |
michael@0 | 104 | |
michael@0 | 105 | // Gaps should result in returning only value until gap hit |
michael@0 | 106 | // (invalid; error recovery) |
michael@0 | 107 | ["attachment; filename=basic; filename*0*=UTF-8''multi;\r\n" |
michael@0 | 108 | + " filename*1=line;\r\n" |
michael@0 | 109 | + " filename*3*=%20extended", |
michael@0 | 110 | "attachment", "multiline", |
michael@0 | 111 | /* "attachment", "basic" */], |
michael@0 | 112 | |
michael@0 | 113 | // First series, only please, and don't slurp up higher elements (*2 in this |
michael@0 | 114 | // case) from later series into earlier one (invalid; error recovery) |
michael@0 | 115 | ["attachment; filename=basic; filename*0*=UTF-8''multi;\r\n" |
michael@0 | 116 | + " filename*1=line;\r\n" |
michael@0 | 117 | + " filename*0*=UTF-8''wrong;\r\n" |
michael@0 | 118 | + " filename*1=bad;\r\n" |
michael@0 | 119 | + " filename*2=evil", |
michael@0 | 120 | "attachment", "multiline", |
michael@0 | 121 | /* "attachment", "basic" */], |
michael@0 | 122 | |
michael@0 | 123 | // RFC 2231 not clear on correct outcome: we prefer non-continued extended |
michael@0 | 124 | // (invalid; error recovery) |
michael@0 | 125 | ["attachment; filename=basic; filename*0=UTF-8''multi\r\n;" |
michael@0 | 126 | + " filename*=UTF-8''extended;\r\n" |
michael@0 | 127 | + " filename*1=line;\r\n" |
michael@0 | 128 | + " filename*2*=%20extended", |
michael@0 | 129 | "attachment", "extended"], |
michael@0 | 130 | |
michael@0 | 131 | // sneaky: if unescaped, make sure we leave UTF-8'' in value |
michael@0 | 132 | ["attachment; filename*0=UTF-8''unescaped;\r\n" |
michael@0 | 133 | + " filename*1*=%20so%20includes%20UTF-8''%20in%20value", |
michael@0 | 134 | "attachment", "UTF-8''unescaped so includes UTF-8'' in value", |
michael@0 | 135 | /* "attachment", Cr.NS_ERROR_INVALID_ARG */], |
michael@0 | 136 | |
michael@0 | 137 | // sneaky: if unescaped, make sure we leave UTF-8'' in value |
michael@0 | 138 | ["attachment; filename=basic; filename*0=UTF-8''unescaped;\r\n" |
michael@0 | 139 | + " filename*1*=%20so%20includes%20UTF-8''%20in%20value", |
michael@0 | 140 | "attachment", "UTF-8''unescaped so includes UTF-8'' in value", |
michael@0 | 141 | /* "attachment", "basic" */], |
michael@0 | 142 | |
michael@0 | 143 | // Prefer basic over invalid continuation |
michael@0 | 144 | // (invalid; error recovery) |
michael@0 | 145 | ["attachment; filename=basic; filename*1=multi;\r\n" |
michael@0 | 146 | + " filename*2=line;\r\n" |
michael@0 | 147 | + " filename*3*=%20extended", |
michael@0 | 148 | "attachment", "basic"], |
michael@0 | 149 | |
michael@0 | 150 | // support digits over 10 |
michael@0 | 151 | ["attachment; filename=basic; filename*0*=UTF-8''0;\r\n" |
michael@0 | 152 | + " filename*1=1; filename*2=2;filename*3=3;filename*4=4;filename*5=5;\r\n" |
michael@0 | 153 | + " filename*6=6; filename*7=7;filename*8=8;filename*9=9;filename*10=a;\r\n" |
michael@0 | 154 | + " filename*11=b; filename*12=c;filename*13=d;filename*14=e;filename*15=f\r\n", |
michael@0 | 155 | "attachment", "0123456789abcdef", |
michael@0 | 156 | /* "attachment", "basic" */], |
michael@0 | 157 | |
michael@0 | 158 | // support digits over 10 (detect gaps) |
michael@0 | 159 | ["attachment; filename=basic; filename*0*=UTF-8''0;\r\n" |
michael@0 | 160 | + " filename*1=1; filename*2=2;filename*3=3;filename*4=4;filename*5=5;\r\n" |
michael@0 | 161 | + " filename*6=6; filename*7=7;filename*8=8;filename*9=9;filename*10=a;\r\n" |
michael@0 | 162 | + " filename*11=b; filename*12=c;filename*14=e\r\n", |
michael@0 | 163 | "attachment", "0123456789abc", |
michael@0 | 164 | /* "attachment", "basic" */], |
michael@0 | 165 | |
michael@0 | 166 | // return nothing: invalid |
michael@0 | 167 | // (invalid; error recovery) |
michael@0 | 168 | ["attachment; filename*1=multi;\r\n" |
michael@0 | 169 | + " filename*2=line;\r\n" |
michael@0 | 170 | + " filename*3*=%20extended", |
michael@0 | 171 | "attachment", Cr.NS_ERROR_INVALID_ARG], |
michael@0 | 172 | |
michael@0 | 173 | // Bug 272541: Empty disposition type treated as "attachment" |
michael@0 | 174 | |
michael@0 | 175 | // sanity check |
michael@0 | 176 | ["attachment; filename=foo.html", |
michael@0 | 177 | "attachment", "foo.html", |
michael@0 | 178 | "attachment", "foo.html"], |
michael@0 | 179 | |
michael@0 | 180 | // the actual bug |
michael@0 | 181 | ["; filename=foo.html", |
michael@0 | 182 | Cr.NS_ERROR_FIRST_HEADER_FIELD_COMPONENT_EMPTY, "foo.html", |
michael@0 | 183 | Cr.NS_ERROR_FIRST_HEADER_FIELD_COMPONENT_EMPTY, "foo.html"], |
michael@0 | 184 | |
michael@0 | 185 | // regression check, but see bug 671204 |
michael@0 | 186 | ["filename=foo.html", |
michael@0 | 187 | "filename=foo.html", "foo.html", |
michael@0 | 188 | "filename=foo.html", "foo.html"], |
michael@0 | 189 | |
michael@0 | 190 | // Bug 384571: RFC 2231 parameters not decoded when appearing in reversed order |
michael@0 | 191 | |
michael@0 | 192 | // check ordering |
michael@0 | 193 | ["attachment; filename=basic; filename*0*=UTF-8''0;\r\n" |
michael@0 | 194 | + " filename*1=1; filename*2=2;filename*3=3;filename*4=4;filename*5=5;\r\n" |
michael@0 | 195 | + " filename*6=6; filename*7=7;filename*8=8;filename*9=9;filename*10=a;\r\n" |
michael@0 | 196 | + " filename*11=b; filename*12=c;filename*13=d;filename*15=f;filename*14=e;\r\n", |
michael@0 | 197 | "attachment", "0123456789abcdef", |
michael@0 | 198 | /* "attachment", "basic" */], |
michael@0 | 199 | |
michael@0 | 200 | // check non-digits in sequence numbers |
michael@0 | 201 | ["attachment; filename=basic; filename*0*=UTF-8''0;\r\n" |
michael@0 | 202 | + " filename*1a=1\r\n", |
michael@0 | 203 | "attachment", "0", |
michael@0 | 204 | /* "attachment", "basic" */], |
michael@0 | 205 | |
michael@0 | 206 | // check duplicate sequence numbers |
michael@0 | 207 | ["attachment; filename=basic; filename*0*=UTF-8''0;\r\n" |
michael@0 | 208 | + " filename*0=bad; filename*1=1;\r\n", |
michael@0 | 209 | "attachment", "0", |
michael@0 | 210 | /* "attachment", "basic" */], |
michael@0 | 211 | |
michael@0 | 212 | // check overflow |
michael@0 | 213 | ["attachment; filename=basic; filename*0*=UTF-8''0;\r\n" |
michael@0 | 214 | + " filename*11111111111111111111111111111111111111111111111111111111111=1", |
michael@0 | 215 | "attachment", "0", |
michael@0 | 216 | /* "attachment", "basic" */], |
michael@0 | 217 | |
michael@0 | 218 | // check underflow |
michael@0 | 219 | ["attachment; filename=basic; filename*0*=UTF-8''0;\r\n" |
michael@0 | 220 | + " filename*-1=1", |
michael@0 | 221 | "attachment", "0", |
michael@0 | 222 | /* "attachment", "basic" */], |
michael@0 | 223 | |
michael@0 | 224 | // check mixed token/quoted-string |
michael@0 | 225 | ["attachment; filename=basic; filename*0=\"0\";\r\n" |
michael@0 | 226 | + " filename*1=1;\r\n" |
michael@0 | 227 | + " filename*2*=%32", |
michael@0 | 228 | "attachment", "012", |
michael@0 | 229 | /* "attachment", "basic" */], |
michael@0 | 230 | |
michael@0 | 231 | // check empty sequence number |
michael@0 | 232 | ["attachment; filename=basic; filename**=UTF-8''0\r\n", |
michael@0 | 233 | "attachment", "basic", |
michael@0 | 234 | "attachment", "basic"], |
michael@0 | 235 | |
michael@0 | 236 | |
michael@0 | 237 | // Bug 419157: ensure that a MIME parameter with no charset information |
michael@0 | 238 | // fallbacks to Latin-1 |
michael@0 | 239 | |
michael@0 | 240 | ["attachment;filename=IT839\x04\xB5(m8)2.pdf;", |
michael@0 | 241 | "attachment", "IT839\u0004\u00b5(m8)2.pdf"], |
michael@0 | 242 | |
michael@0 | 243 | // Bug 588389: unescaping backslashes in quoted string parameters |
michael@0 | 244 | |
michael@0 | 245 | // '\"', should be parsed as '"' |
michael@0 | 246 | ["attachment; filename=" + DQUOTE + (BS + DQUOTE) + DQUOTE, |
michael@0 | 247 | "attachment", DQUOTE], |
michael@0 | 248 | |
michael@0 | 249 | // 'a\"b', should be parsed as 'a"b' |
michael@0 | 250 | ["attachment; filename=" + DQUOTE + 'a' + (BS + DQUOTE) + 'b' + DQUOTE, |
michael@0 | 251 | "attachment", "a" + DQUOTE + "b"], |
michael@0 | 252 | |
michael@0 | 253 | // '\x', should be parsed as 'x' |
michael@0 | 254 | ["attachment; filename=" + DQUOTE + (BS + "x") + DQUOTE, |
michael@0 | 255 | "attachment", "x"], |
michael@0 | 256 | |
michael@0 | 257 | // test empty param (quoted-string) |
michael@0 | 258 | ["attachment; filename=" + DQUOTE + DQUOTE, |
michael@0 | 259 | "attachment", ""], |
michael@0 | 260 | |
michael@0 | 261 | // test empty param |
michael@0 | 262 | ["attachment; filename=", |
michael@0 | 263 | "attachment", ""], |
michael@0 | 264 | |
michael@0 | 265 | // Bug 601933: RFC 2047 does not apply to parameters (at least in HTTP) |
michael@0 | 266 | ["attachment; filename==?ISO-8859-1?Q?foo-=E4.html?=", |
michael@0 | 267 | "attachment", "foo-\u00e4.html", |
michael@0 | 268 | /* "attachment", "=?ISO-8859-1?Q?foo-=E4.html?=" */], |
michael@0 | 269 | |
michael@0 | 270 | ["attachment; filename=\"=?ISO-8859-1?Q?foo-=E4.html?=\"", |
michael@0 | 271 | "attachment", "foo-\u00e4.html", |
michael@0 | 272 | /* "attachment", "=?ISO-8859-1?Q?foo-=E4.html?=" */], |
michael@0 | 273 | |
michael@0 | 274 | // format sent by GMail as of 2012-07-23 (5987 overrides 2047) |
michael@0 | 275 | ["attachment; filename=\"=?ISO-8859-1?Q?foo-=E4.html?=\"; filename*=UTF-8''5987", |
michael@0 | 276 | "attachment", "5987"], |
michael@0 | 277 | |
michael@0 | 278 | // Bug 651185: double quotes around 2231/5987 encoded param |
michael@0 | 279 | // Change reverted to backwards compat issues with various web services, |
michael@0 | 280 | // such as OWA (Bug 703015), plus similar problems in Thunderbird. If this |
michael@0 | 281 | // is tried again in the future, email probably needs to be special-cased. |
michael@0 | 282 | |
michael@0 | 283 | // sanity check |
michael@0 | 284 | ["attachment; filename*=utf-8''%41", |
michael@0 | 285 | "attachment", "A"], |
michael@0 | 286 | |
michael@0 | 287 | // the actual bug |
michael@0 | 288 | ["attachment; filename*=" + DQUOTE + "utf-8''%41" + DQUOTE, |
michael@0 | 289 | "attachment", "A"], |
michael@0 | 290 | // previously with the fix for 651185: |
michael@0 | 291 | // "attachment", Cr.NS_ERROR_INVALID_ARG], |
michael@0 | 292 | |
michael@0 | 293 | // Bug 670333: Content-Disposition parser does not require presence of "=" |
michael@0 | 294 | // in params |
michael@0 | 295 | |
michael@0 | 296 | // sanity check |
michael@0 | 297 | ["attachment; filename*=UTF-8''foo-%41.html", |
michael@0 | 298 | "attachment", "foo-A.html"], |
michael@0 | 299 | |
michael@0 | 300 | // the actual bug |
michael@0 | 301 | ["attachment; filename *=UTF-8''foo-%41.html", |
michael@0 | 302 | "attachment", Cr.NS_ERROR_INVALID_ARG], |
michael@0 | 303 | |
michael@0 | 304 | // the actual bug, without 2231/5987 encoding |
michael@0 | 305 | ["attachment; filename X", |
michael@0 | 306 | "attachment", Cr.NS_ERROR_INVALID_ARG], |
michael@0 | 307 | |
michael@0 | 308 | // sanity check with WS on both sides |
michael@0 | 309 | ["attachment; filename = foo-A.html", |
michael@0 | 310 | "attachment", "foo-A.html"], |
michael@0 | 311 | |
michael@0 | 312 | // Bug 685192: in RFC2231/5987 encoding, a missing charset field should be |
michael@0 | 313 | // treated as error |
michael@0 | 314 | |
michael@0 | 315 | // the actual bug |
michael@0 | 316 | ["attachment; filename*=''foo", |
michael@0 | 317 | "attachment", "foo"], |
michael@0 | 318 | // previously with the fix for 692574: |
michael@0 | 319 | // "attachment", Cr.NS_ERROR_INVALID_ARG], |
michael@0 | 320 | |
michael@0 | 321 | // sanity check |
michael@0 | 322 | ["attachment; filename*=a''foo", |
michael@0 | 323 | "attachment", "foo"], |
michael@0 | 324 | |
michael@0 | 325 | // Bug 692574: RFC2231/5987 decoding should not tolerate missing single |
michael@0 | 326 | // quotes |
michael@0 | 327 | |
michael@0 | 328 | // one missing |
michael@0 | 329 | ["attachment; filename*=UTF-8'foo-%41.html", |
michael@0 | 330 | "attachment", "foo-A.html"], |
michael@0 | 331 | // previously with the fix for 692574: |
michael@0 | 332 | // "attachment", Cr.NS_ERROR_INVALID_ARG], |
michael@0 | 333 | |
michael@0 | 334 | // both missing |
michael@0 | 335 | ["attachment; filename*=foo-%41.html", |
michael@0 | 336 | "attachment","foo-A.html"], |
michael@0 | 337 | // previously with the fix for 692574: |
michael@0 | 338 | // "attachment", Cr.NS_ERROR_INVALID_ARG], |
michael@0 | 339 | |
michael@0 | 340 | // make sure fallback works |
michael@0 | 341 | ["attachment; filename*=UTF-8'foo-%41.html; filename=bar.html", |
michael@0 | 342 | "attachment", "foo-A.html"], |
michael@0 | 343 | // previously with the fix for 692574: |
michael@0 | 344 | // "attachment", "bar.html"], |
michael@0 | 345 | |
michael@0 | 346 | // Bug 693806: RFC2231/5987 encoding: charset information should be treated |
michael@0 | 347 | // as authoritative |
michael@0 | 348 | |
michael@0 | 349 | // UTF-8 labeled ISO-8859-1 |
michael@0 | 350 | ["attachment; filename*=ISO-8859-1''%c3%a4", |
michael@0 | 351 | "attachment", "\u00c3\u00a4"], |
michael@0 | 352 | |
michael@0 | 353 | // UTF-8 labeled ISO-8859-1, but with octets not allowed in ISO-8859-1 |
michael@0 | 354 | // accepts x82, understands it as Win1252, maps it to Unicode \u20a1 |
michael@0 | 355 | ["attachment; filename*=ISO-8859-1''%e2%82%ac", |
michael@0 | 356 | "attachment", "\u00e2\u201a\u00ac"], |
michael@0 | 357 | |
michael@0 | 358 | // defective UTF-8 |
michael@0 | 359 | ["attachment; filename*=UTF-8''A%e4B", |
michael@0 | 360 | "attachment", Cr.NS_ERROR_INVALID_ARG], |
michael@0 | 361 | |
michael@0 | 362 | // defective UTF-8, with fallback |
michael@0 | 363 | ["attachment; filename*=UTF-8''A%e4B; filename=fallback", |
michael@0 | 364 | "attachment", "fallback"], |
michael@0 | 365 | |
michael@0 | 366 | // defective UTF-8 (continuations), with fallback |
michael@0 | 367 | ["attachment; filename*0*=UTF-8''A%e4B; filename=fallback", |
michael@0 | 368 | "attachment", "fallback"], |
michael@0 | 369 | |
michael@0 | 370 | // check that charsets aren't mixed up |
michael@0 | 371 | ["attachment; filename*0*=ISO-8859-15''euro-sign%3d%a4; filename*=ISO-8859-1''currency-sign%3d%a4", |
michael@0 | 372 | "attachment", "currency-sign=\u00a4"], |
michael@0 | 373 | |
michael@0 | 374 | // same as above, except reversed |
michael@0 | 375 | ["attachment; filename*=ISO-8859-1''currency-sign%3d%a4; filename*0*=ISO-8859-15''euro-sign%3d%a4", |
michael@0 | 376 | "attachment", "currency-sign=\u00a4"], |
michael@0 | 377 | |
michael@0 | 378 | // Bug 704989: add workaround for broken Outlook Web App (OWA) |
michael@0 | 379 | // attachment handling |
michael@0 | 380 | |
michael@0 | 381 | ["attachment; filename*=\"a%20b\"", |
michael@0 | 382 | "attachment", "a b"], |
michael@0 | 383 | |
michael@0 | 384 | // Bug 717121: crash nsMIMEHeaderParamImpl::DoParameterInternal |
michael@0 | 385 | |
michael@0 | 386 | ["attachment; filename=\"", |
michael@0 | 387 | "attachment", ""], |
michael@0 | 388 | |
michael@0 | 389 | // We used to read past string if last param w/o = and ; |
michael@0 | 390 | // Note: was only detected on windows PGO builds |
michael@0 | 391 | ["attachment; filename=foo; trouble", |
michael@0 | 392 | "attachment", "foo"], |
michael@0 | 393 | |
michael@0 | 394 | // Same, followed by space, hits another case |
michael@0 | 395 | ["attachment; filename=foo; trouble ", |
michael@0 | 396 | "attachment", "foo"], |
michael@0 | 397 | |
michael@0 | 398 | ["attachment", |
michael@0 | 399 | "attachment", Cr.NS_ERROR_INVALID_ARG], |
michael@0 | 400 | |
michael@0 | 401 | // Bug 730574: quoted-string in RFC2231-continuations not handled |
michael@0 | 402 | |
michael@0 | 403 | ['attachment; filename=basic; filename*0="foo"; filename*1="\\b\\a\\r.html"', |
michael@0 | 404 | "attachment", "foobar.html", |
michael@0 | 405 | /* "attachment", "basic" */], |
michael@0 | 406 | |
michael@0 | 407 | // unmatched escape char |
michael@0 | 408 | ['attachment; filename=basic; filename*0="foo"; filename*1="\\b\\a\\', |
michael@0 | 409 | "attachment", "fooba\\", |
michael@0 | 410 | /* "attachment", "basic" */], |
michael@0 | 411 | |
michael@0 | 412 | // Bug 732369: Content-Disposition parser does not require presence of ";" between params |
michael@0 | 413 | // optimally, this would not even return the disposition type "attachment" |
michael@0 | 414 | |
michael@0 | 415 | ["attachment; extension=bla filename=foo", |
michael@0 | 416 | "attachment", Cr.NS_ERROR_INVALID_ARG], |
michael@0 | 417 | |
michael@0 | 418 | ["attachment; filename=foo extension=bla", |
michael@0 | 419 | "attachment", "foo"], |
michael@0 | 420 | |
michael@0 | 421 | ["attachment filename=foo", |
michael@0 | 422 | "attachment", Cr.NS_ERROR_INVALID_ARG], |
michael@0 | 423 | |
michael@0 | 424 | // Bug 777687: handling of broken %escapes |
michael@0 | 425 | |
michael@0 | 426 | ["attachment; filename*=UTF-8''f%oo; filename=bar", |
michael@0 | 427 | "attachment", "bar"], |
michael@0 | 428 | |
michael@0 | 429 | ["attachment; filename*=UTF-8''foo%; filename=bar", |
michael@0 | 430 | "attachment", "bar"], |
michael@0 | 431 | |
michael@0 | 432 | // Bug 783502 - xpcshell test netwerk/test/unit/test_MIME_params.js fails on AddressSanitizer |
michael@0 | 433 | ['attachment; filename="\\b\\a\\', |
michael@0 | 434 | "attachment", "ba\\"], |
michael@0 | 435 | ]; |
michael@0 | 436 | |
michael@0 | 437 | var rfc5987paramtests = [ |
michael@0 | 438 | [ // basic test |
michael@0 | 439 | "UTF-8'language'value", "value", "language", Cr.NS_OK ], |
michael@0 | 440 | [ // percent decoding |
michael@0 | 441 | "UTF-8''1%202", "1 2", "", Cr.NS_OK ], |
michael@0 | 442 | [ // UTF-8 |
michael@0 | 443 | "UTF-8''%c2%a3%20and%20%e2%82%ac%20rates", "\u00a3 and \u20ac rates", "", Cr.NS_OK ], |
michael@0 | 444 | [ // missing charset |
michael@0 | 445 | "''abc", "", "", Cr.NS_ERROR_INVALID_ARG ], |
michael@0 | 446 | [ // ISO-8859-1: unsupported |
michael@0 | 447 | "ISO-8859-1''%A3%20rates", "", "", Cr.NS_ERROR_INVALID_ARG ], |
michael@0 | 448 | [ // unknown charset |
michael@0 | 449 | "foo''abc", "", "", Cr.NS_ERROR_INVALID_ARG ], |
michael@0 | 450 | [ // missing component |
michael@0 | 451 | "abc", "", "", Cr.NS_ERROR_INVALID_ARG ], |
michael@0 | 452 | [ // missing component |
michael@0 | 453 | "'abc", "", "", Cr.NS_ERROR_INVALID_ARG ], |
michael@0 | 454 | [ // illegal chars |
michael@0 | 455 | "UTF-8''a b", "", "", Cr.NS_ERROR_INVALID_ARG ], |
michael@0 | 456 | [ // broken % escapes |
michael@0 | 457 | "UTF-8''a%zz", "", "", Cr.NS_ERROR_INVALID_ARG ], |
michael@0 | 458 | [ // broken % escapes |
michael@0 | 459 | "UTF-8''a%b", "", "", Cr.NS_ERROR_INVALID_ARG ], |
michael@0 | 460 | [ // broken % escapes |
michael@0 | 461 | "UTF-8''a%", "", "", Cr.NS_ERROR_INVALID_ARG ], |
michael@0 | 462 | [ // broken UTF-8 |
michael@0 | 463 | "UTF-8''%A3%20rates", "", "", 0x8050000E /* NS_ERROR_UDEC_ILLEGALINPUT */ ], |
michael@0 | 464 | ]; |
michael@0 | 465 | |
michael@0 | 466 | function do_tests(whichRFC) |
michael@0 | 467 | { |
michael@0 | 468 | var mhp = Components.classes["@mozilla.org/network/mime-hdrparam;1"] |
michael@0 | 469 | .getService(Components.interfaces.nsIMIMEHeaderParam); |
michael@0 | 470 | |
michael@0 | 471 | var unused = { value : null }; |
michael@0 | 472 | |
michael@0 | 473 | for (var i = 0; i < tests.length; ++i) { |
michael@0 | 474 | dump("Testing #" + i + ": " + tests[i] + "\n"); |
michael@0 | 475 | |
michael@0 | 476 | // check disposition type |
michael@0 | 477 | var expectedDt = tests[i].length == 3 || whichRFC == 0 ? tests[i][1] : tests[i][3]; |
michael@0 | 478 | |
michael@0 | 479 | try { |
michael@0 | 480 | var result; |
michael@0 | 481 | |
michael@0 | 482 | if (whichRFC == 0) |
michael@0 | 483 | result = mhp.getParameter(tests[i][0], "", "UTF-8", true, unused); |
michael@0 | 484 | else |
michael@0 | 485 | result = mhp.getParameterHTTP(tests[i][0], "", "UTF-8", true, unused); |
michael@0 | 486 | |
michael@0 | 487 | do_check_eq(result, expectedDt); |
michael@0 | 488 | } |
michael@0 | 489 | catch (e) { |
michael@0 | 490 | // Tests can also succeed by expecting to fail with given error code |
michael@0 | 491 | if (e.result) { |
michael@0 | 492 | // Allow following tests to run by catching exception from do_check_eq() |
michael@0 | 493 | try { |
michael@0 | 494 | do_check_eq(e.result, expectedDt); |
michael@0 | 495 | } catch(e) {} |
michael@0 | 496 | } |
michael@0 | 497 | continue; |
michael@0 | 498 | } |
michael@0 | 499 | |
michael@0 | 500 | // check filename parameter |
michael@0 | 501 | var expectedFn = tests[i].length == 3 || whichRFC == 0 ? tests[i][2] : tests[i][4]; |
michael@0 | 502 | |
michael@0 | 503 | try { |
michael@0 | 504 | var result; |
michael@0 | 505 | |
michael@0 | 506 | if (whichRFC == 0) |
michael@0 | 507 | result = mhp.getParameter(tests[i][0], "filename", "UTF-8", true, unused); |
michael@0 | 508 | else |
michael@0 | 509 | result = mhp.getParameterHTTP(tests[i][0], "filename", "UTF-8", true, unused); |
michael@0 | 510 | |
michael@0 | 511 | do_check_eq(result, expectedFn); |
michael@0 | 512 | } |
michael@0 | 513 | catch (e) { |
michael@0 | 514 | // Tests can also succeed by expecting to fail with given error code |
michael@0 | 515 | if (e.result) { |
michael@0 | 516 | // Allow following tests to run by catching exception from do_check_eq() |
michael@0 | 517 | try { |
michael@0 | 518 | do_check_eq(e.result, expectedFn); |
michael@0 | 519 | } catch(e) {} |
michael@0 | 520 | } |
michael@0 | 521 | continue; |
michael@0 | 522 | } |
michael@0 | 523 | } |
michael@0 | 524 | } |
michael@0 | 525 | |
michael@0 | 526 | function test_decode5987Param() { |
michael@0 | 527 | var mhp = Components.classes["@mozilla.org/network/mime-hdrparam;1"] |
michael@0 | 528 | .getService(Components.interfaces.nsIMIMEHeaderParam); |
michael@0 | 529 | |
michael@0 | 530 | for (var i = 0; i < rfc5987paramtests.length; ++i) { |
michael@0 | 531 | dump("Testing #" + i + ": " + rfc5987paramtests[i] + "\n"); |
michael@0 | 532 | |
michael@0 | 533 | var lang = {}; |
michael@0 | 534 | try { |
michael@0 | 535 | var decoded = mhp.decodeRFC5987Param(rfc5987paramtests[i][0], lang); |
michael@0 | 536 | if (rfc5987paramtests[i][3] == Cr.NS_OK) { |
michael@0 | 537 | do_check_eq(rfc5987paramtests[i][1], decoded); |
michael@0 | 538 | do_check_eq(rfc5987paramtests[i][2], lang.value); |
michael@0 | 539 | } |
michael@0 | 540 | else { |
michael@0 | 541 | do_check_eq(rfc5987paramtests[i][3], "instead got: " + decoded); |
michael@0 | 542 | } |
michael@0 | 543 | } |
michael@0 | 544 | catch (e) { |
michael@0 | 545 | do_check_eq(rfc5987paramtests[i][3], e.result); |
michael@0 | 546 | } |
michael@0 | 547 | } |
michael@0 | 548 | } |
michael@0 | 549 | |
michael@0 | 550 | function run_test() { |
michael@0 | 551 | |
michael@0 | 552 | // Test RFC 2231 (complete header field values) |
michael@0 | 553 | do_tests(0); |
michael@0 | 554 | |
michael@0 | 555 | // Test RFC 5987 (complete header field values) |
michael@0 | 556 | do_tests(1); |
michael@0 | 557 | |
michael@0 | 558 | // tests for RFC5987 parameter parsing |
michael@0 | 559 | test_decode5987Param(); |
michael@0 | 560 | } |