From 2ab6cbd51b3bffd609ebd5a8864c546f3f7e6ea0 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 15 Aug 2017 12:43:32 +0200 Subject: [PATCH 01/20] data: URL tests Tests for https://github.com/whatwg/fetch/pull/579. --- fetch/data-urls/README.md | 5 + fetch/data-urls/base64.any.js | 16 ++ fetch/data-urls/resources/base64.json | 73 ++++++++++ html/webappapis/atob/base64.html | 201 +++++--------------------- 4 files changed, 128 insertions(+), 167 deletions(-) create mode 100644 fetch/data-urls/README.md create mode 100644 fetch/data-urls/base64.any.js create mode 100644 fetch/data-urls/resources/base64.json diff --git a/fetch/data-urls/README.md b/fetch/data-urls/README.md new file mode 100644 index 00000000000000..27084efaeca5cd --- /dev/null +++ b/fetch/data-urls/README.md @@ -0,0 +1,5 @@ +== Forgiving-base64 decode == + +`resources/base64.json` contains [forgiving-base64 decode](https://infra.spec.whatwg.org/#forgiving-base64-decode) tests. The tests are encoded as a list. Each item in the list is a list of two items. The first item describes the input, the second item describes the output as a list of integers representing bytes or null if the input cannot be decoded. + +These tests are used for `data:` URLs in this directory (see `base64.any.js`) and `window.atob()` in `../../html/webappapis/atob/base64.html`. diff --git a/fetch/data-urls/base64.any.js b/fetch/data-urls/base64.any.js new file mode 100644 index 00000000000000..48e4c530a86225 --- /dev/null +++ b/fetch/data-urls/base64.any.js @@ -0,0 +1,16 @@ +promise_test(() => fetch("resources/base64.json").then(res => res.json()).then(runBase64Tests), "Setup."); +function runBase64Tests(tests) { + for(let i = 0; i < tests.length; i++) { + const input = tests[i][0], + output = tests[i][1], + dataURL = "data:;base64," + input; + promise_test(t => { + if(output === null) { + return promise_rejects(t, new TypeError(), fetch(dataURL)); + } + return fetch(dataURL).then(res => res.arrayBuffer()).then(body => { + assert_array_equals(new Uint8Array(body), output); + }); + }, "data: URL base64 handling: " + format_value(input)); + } +} diff --git a/fetch/data-urls/resources/base64.json b/fetch/data-urls/resources/base64.json new file mode 100644 index 00000000000000..4c7b81d7886327 --- /dev/null +++ b/fetch/data-urls/resources/base64.json @@ -0,0 +1,73 @@ +[ + ["", []], + ["abcd", [105, 183, 29]], + [" abcd", [105, 183, 29]], + ["abcd ", [105, 183, 29]], + [" abcd===", null], + ["abcd=== ", null], + ["abcd ===", null], + ["a", null], + ["ab", [105]], + ["abc", [105, 183]], + ["abcde", null], + ["𐀀", null], + ["=", null], + ["==", null], + ["===", null], + ["====", null], + ["=====", null], + ["a=", null], + ["a==", null], + ["a===", null], + ["a====", null], + ["a=====", null], + ["ab=", null], + ["ab==", [105]], + ["ab===", null], + ["ab====", null], + ["ab=====", null], + ["abc=", [105, 183]], + ["abc==", null], + ["abc===", null], + ["abc====", null], + ["abc=====", null], + ["abcd=", null], + ["abcd==", null], + ["abcd===", null], + ["abcd====", null], + ["abcd=====", null], + ["abcde=", null], + ["abcde==", null], + ["abcde===", null], + ["abcde====", null], + ["abcde=====", null], + ["=a", null], + ["=a=", null], + ["a=b", null], + ["a=b=", null], + ["ab=c", null], + ["ab=c=", null], + ["abc=d", null], + ["abc=d=", null], + ["ab\tcd", [105, 183, 29]], + ["ab\ncd", [105, 183, 29]], + ["ab\fcd", [105, 183, 29]], + ["ab\rcd", [105, 183, 29]], + ["ab cd", [105, 183, 29]], + ["ab\u00a0cd", null], + ["ab\t\n\f\r cd", [105, 183, 29]], + [" \t\n\f\r ab\t\n\f\r cd\t\n\f\r ", [105, 183, 29]], + ["ab\t\n\f\r =\t\n\f\r =\t\n\f\r ", [105]], + ["A", null], + ["/A", [252]], + ["//A", [255, 240]], + ["///A", [255, 255, 192]], + ["////A", null], + ["/", null], + ["A/", [3]], + ["AA/", [0, 15]], + ["AAAA/", null], + ["AAA/", [0, 0, 63]], + ["\u0000nonsense", null], + ["abcd\u0000nonsense", null] +] diff --git a/html/webappapis/atob/base64.html b/html/webappapis/atob/base64.html index c33ab228f94a95..c522afdd56c7ca 100644 --- a/html/webappapis/atob/base64.html +++ b/html/webappapis/atob/base64.html @@ -70,124 +70,6 @@ // Throw INVALID_CHARACTER_ERR exception here -- won't be hit in the tests. } -/** - * Implementation of atob() according to the HTML spec, except that instead of - * throwing INVALID_CHARACTER_ERR we return null. - */ -function myatob(input) { - // WebIDL requires DOMStrings to just be converted using ECMAScript - // ToString, which in our case amounts to calling String(). - input = String(input); - - // "Remove all space characters from input." - input = input.replace(/[ \t\n\f\r]/g, ""); - - // "If the length of input divides by 4 leaving no remainder, then: if - // input ends with one or two U+003D EQUALS SIGN (=) characters, remove - // them from input." - if (input.length % 4 == 0 && /==?$/.test(input)) { - input = input.replace(/==?$/, ""); - } - - // "If the length of input divides by 4 leaving a remainder of 1, throw an - // INVALID_CHARACTER_ERR exception and abort these steps." - // - // "If input contains a character that is not in the following list of - // characters and character ranges, throw an INVALID_CHARACTER_ERR - // exception and abort these steps: - // - // U+002B PLUS SIGN (+) - // U+002F SOLIDUS (/) - // U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9) - // U+0041 LATIN CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER Z - // U+0061 LATIN SMALL LETTER A to U+007A LATIN SMALL LETTER Z" - if (input.length % 4 == 1 - || !/^[+/0-9A-Za-z]*$/.test(input)) { - return null; - } - - // "Let output be a string, initially empty." - var output = ""; - - // "Let buffer be a buffer that can have bits appended to it, initially - // empty." - // - // We append bits via left-shift and or. accumulatedBits is used to track - // when we've gotten to 24 bits. - var buffer = 0; - var accumulatedBits = 0; - - // "While position does not point past the end of input, run these - // substeps:" - for (var i = 0; i < input.length; i++) { - // "Find the character pointed to by position in the first column of - // the following table. Let n be the number given in the second cell of - // the same row." - // - // "Append to buffer the six bits corresponding to number, most - // significant bit first." - // - // atobLookup() implements the table from the spec. - buffer <<= 6; - buffer |= atobLookup(input[i]); - - // "If buffer has accumulated 24 bits, interpret them as three 8-bit - // big-endian numbers. Append the three characters with code points - // equal to those numbers to output, in the same order, and then empty - // buffer." - accumulatedBits += 6; - if (accumulatedBits == 24) { - output += String.fromCharCode((buffer & 0xff0000) >> 16); - output += String.fromCharCode((buffer & 0xff00) >> 8); - output += String.fromCharCode(buffer & 0xff); - buffer = accumulatedBits = 0; - } - - // "Advance position by one character." - } - - // "If buffer is not empty, it contains either 12 or 18 bits. If it - // contains 12 bits, discard the last four and interpret the remaining - // eight as an 8-bit big-endian number. If it contains 18 bits, discard the - // last two and interpret the remaining 16 as two 8-bit big-endian numbers. - // Append the one or two characters with code points equal to those one or - // two numbers to output, in the same order." - if (accumulatedBits == 12) { - buffer >>= 4; - output += String.fromCharCode(buffer); - } else if (accumulatedBits == 18) { - buffer >>= 2; - output += String.fromCharCode((buffer & 0xff00) >> 8); - output += String.fromCharCode(buffer & 0xff); - } - - // "Return output." - return output; -} - -/** - * A lookup table for atob(), which converts an ASCII character to the - * corresponding six-bit number. - */ -function atobLookup(chr) { - if (/[A-Z]/.test(chr)) { - return chr.charCodeAt(0) - "A".charCodeAt(0); - } - if (/[a-z]/.test(chr)) { - return chr.charCodeAt(0) - "a".charCodeAt(0) + 26; - } - if (/[0-9]/.test(chr)) { - return chr.charCodeAt(0) - "0".charCodeAt(0) + 52; - } - if (chr == "+") { - return 62; - } - if (chr == "/") { - return 63; - } - // Throw exception; should not be hit in tests -} - function btoaException(input) { input = String(input); for (var i = 0; i < input.length; i++) { @@ -252,55 +134,40 @@ generate_tests(testBtoa, tests); -function testAtob(input) { - var expected = myatob(input); - if (expected === null) { - assert_throws("InvalidCharacterError", function() { atob(input) }); - return; - } - - assert_equals(atob(input), expected); -} - -var tests = ["", "abcd", " abcd", "abcd ", " abcd===", "abcd=== ", - "abcd ===", "a", "ab", "abc", "abcde", String.fromCharCode(0xd800, 0xdc00), - "=", "==", "===", "====", "=====", - "a=", "a==", "a===", "a====", "a=====", - "ab=", "ab==", "ab===", "ab====", "ab=====", - "abc=", "abc==", "abc===", "abc====", "abc=====", - "abcd=", "abcd==", "abcd===", "abcd====", "abcd=====", - "abcde=", "abcde==", "abcde===", "abcde====", "abcde=====", - "=a", "=a=", "a=b", "a=b=", "ab=c", "ab=c=", "abc=d", "abc=d=", - // With whitespace - "ab\tcd", "ab\ncd", "ab\fcd", "ab\rcd", "ab cd", "ab\u00a0cd", - "ab\t\n\f\r cd", " \t\n\f\r ab\t\n\f\r cd\t\n\f\r ", - "ab\t\n\f\r =\t\n\f\r =\t\n\f\r ", - // Test if any bits are set at the end. These should all be fine, since - // they end with A, which becomes 0: - "A", "/A", "//A", "///A", "////A", - // These are all bad, since they end in / (= 63, all bits set) but their - // length isn't a multiple of four characters, so they can't be output by - // btoa(). Thus one might expect some UAs to throw exceptions or otherwise - // object, since they could never be output by btoa(), so they're good to - // test. - "/", "A/", "AA/", "AAAA/", - // But this one is possible: - "AAA/", - // Binary-safety tests - "\0nonsense", "abcd\0nonsense", - // WebIDL tests - undefined, null, 7, 12, 1.5, true, false, NaN, +Infinity, -Infinity, 0, -0, - {toString: function() { return "foo" }}, - {toString: function() { return "abcd" }}, +promise_test(() => fetch("../../../fetch/data-urls/resources/base64.json").then(res => res.json()).then(runAtobTests), "atob() setup."); + +const idlTests = [ + [undefined, null], + [null, [158, 233, 101]], + [7, null], + [12, [215]], + [1.5, null], + [true, [182, 187]], + [false, null], + [NaN, [53, 163]], + [+Infinity, [34, 119, 226, 158, 43, 114]], + [-Infinity, null], + [0, null], + [-0, null], + [{toString: function() { return "foo" }}, [126, 138]], + [{toString: function() { return "abcd" }}, [105, 183, 29]] ]; -tests = tests.map( - function(elem) { - if (myatob(elem) === null) { - return ["atob(" + format_value(elem) + ") must raise InvalidCharacterError", elem]; - } - return ["atob(" + format_value(elem) + ") == " + format_value(myatob(elem)), elem]; - } -); -generate_tests(testAtob, tests); +function runAtobTests(tests) { + const allTests = tests.concat(idlTests); + for(let i = 0; i < allTests.length; i++) { + const input = allTests[i][0], + output = allTests[i][1]; + test(() => { + if(output === null) { + assert_throws("InvalidCharacterError", () => window.atob(input)); + } else { + const result = window.atob(input); + for(let ii = 0; ii < output.length; ii++) { + assert_equals(result.charCodeAt(ii), output[ii]); + } + } + }, "atob(" + format_value(input) + ")"); + } +} From 5b1e17041b8a95a3ad584df1364d763257bbeb79 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 15 Aug 2017 15:21:47 +0200 Subject: [PATCH 02/20] Add data URL tests --- fetch/data-urls/README.md | 8 +- fetch/data-urls/processing.any.js | 23 +++++ fetch/data-urls/resources/data-urls.json | 124 +++++++++++++++++++++++ 3 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 fetch/data-urls/processing.any.js create mode 100644 fetch/data-urls/resources/data-urls.json diff --git a/fetch/data-urls/README.md b/fetch/data-urls/README.md index 27084efaeca5cd..295ccf17493dc8 100644 --- a/fetch/data-urls/README.md +++ b/fetch/data-urls/README.md @@ -1,5 +1,11 @@ +== data: URLs == + +`resources/data-urls.json` contains `data:` URL tests. The tests are encoded as a JSON array. Each value in the array is an array of two are three values. The first value describes the input, the second value describes the expected MIME type, null if the input is expected to fail somehow, or the empty string if the expected value is `text/plain;charset=US-ASCII`. The third value, if present, describes the expected body as an array of integers representing bytes. + +These tests are used for `data:` URLs in this directory (see `processing.any.js`). + == Forgiving-base64 decode == -`resources/base64.json` contains [forgiving-base64 decode](https://infra.spec.whatwg.org/#forgiving-base64-decode) tests. The tests are encoded as a list. Each item in the list is a list of two items. The first item describes the input, the second item describes the output as a list of integers representing bytes or null if the input cannot be decoded. +`resources/base64.json` contains [forgiving-base64 decode](https://infra.spec.whatwg.org/#forgiving-base64-decode) tests. The tests are encoded as a JSON array. Each value in the array is an array of two values. The first value describes the input, the second value describes the output as an array of integers representing bytes or null if the input cannot be decoded. These tests are used for `data:` URLs in this directory (see `base64.any.js`) and `window.atob()` in `../../html/webappapis/atob/base64.html`. diff --git a/fetch/data-urls/processing.any.js b/fetch/data-urls/processing.any.js new file mode 100644 index 00000000000000..5b8500969763aa --- /dev/null +++ b/fetch/data-urls/processing.any.js @@ -0,0 +1,23 @@ +promise_test(() => fetch("resources/data-urls.json").then(res => res.json()).then(runDataURLTests), "Setup."); +function runDataURLTests(tests) { + for(let i = 0; i < tests.length; i++) { + const input = tests[i][0]; + let expectedMimeType = tests[i][1]; + const expectedBody = expectedMimeType !== null ? tests[i][2] : null; + promise_test(t => { + if(expectedMimeType === "") { + expectedMimeType = "text/plain;charset=US-ASCII"; + } + if(expectedMimeType === null) { + return promise_rejects(t, new TypeError(), fetch(input)); + } else { + return fetch(input).then(res => { + return res.arrayBuffer().then(body => { + assert_array_equals(new Uint8Array(body), expectedBody); + assert_equals(res.headers.get("content-type"), expectedMimeType); // We could assert this earlier, but this fails often + }); + }); + } + }, format_value(input)); + } +} diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json new file mode 100644 index 00000000000000..f58ffc80b6688e --- /dev/null +++ b/fetch/data-urls/resources/data-urls.json @@ -0,0 +1,124 @@ +[ + ["data://test/,X", + "", + [88]], + ["data://test:test/,X", + null], + ["data:,X", + "", + [88]], + ["data:,X#X", + "", + [88]], + ["data:,%FF", + "", + [255]], + ["data:text/plain,X", + "text/plain", + [88]], + ["data:text/plain ,X", + "text/plain", + [88]], + ["data:text/plain%20,X", + "text/plain", + [88]], + ["data:text/plain\f,X", + "text/plain", + [88]], + ["data:text/plain%0C,X", + "text/plain", + [88]], + ["data:text/plain;,X", + "text/plain;", + [88]], + ["data:;x=x;charset=x,X", + "", + [88]], + ["data:;x=x,X", + "", + [88]], + ["data:text/plain;charset=windows-1252,%C2%B1", + "text/plain;charset=windows-1252", + [194, 177]], + ["data:text/plain;Charset=UTF-8,%C2%B1", + "text/plain;Charset=UTF-8", + [194, 177]], + ["data:image/gif,%C2%B1", + "image/gif", + [194, 177]], + ["data:IMAGE/gif,%C2%B1", + "IMAGE/gif", + [194, 177]], + ["data:IMAGE/gif;hi=x,%C2%B1", + "IMAGE/gif;hi=x", + [194, 177]], + ["data:IMAGE/gif;CHARSET=x,%C2%B1", + "IMAGE/gif;CHARSET=x", + [194, 177]], + ["data: ,%FF", + "", + [255]], + ["data:%20,%FF", + "", + [255]], + ["data:\f,%FF", + "", + [255]], + ["data:%1F,%FF", + "", + [255]], + ["data:\u0000,%FF", + "", + [255]], + ["data:%00,%FF", + "", + [255]], + ["data:text/html ,X", + "text/html", + [88]], + ["data:†,X", + "", + [88]], + ["data:†/†,X", + "", + [88]], + ["data:X,X", + "", + [88]], + ["data:image/png,X X", + "image/png", + [88, 32, 88]], + ["data:application/xml,X X", + "application/xml", + [88, 32, 88]], + ["data:unknown/unknown,X X", + "unknown/unknown", + [88, 32, 88]], + ["data:text/plain;a=\",\",X", + "data:text/plain;a=\",\"", + [88]], + ["data:text/plain;a=%2C,X", + "data:text/plain;a=,", + [88]], + ["data:;base64,W%20A", + "", + [88]], + ["data:;base64,W%0CA", + "", + [88]], + ["data:x;base64x,WA", + "", + [87, 65]], + ["data:x;base64;x,WA", + "", + [88]], + ["data:x;base64=x,WA", + "", + [87, 65]], + ["data:;charset=x,X", + "text/plain;charset=x", + [88]], + ["data:;charset=\"x\",X", + "text/plain;charset=\"x\"", + [88]] +] From 0c167bff6f51a1ddffab572325e564101e5c6a3a Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 16 Aug 2017 10:07:44 +0200 Subject: [PATCH 03/20] more data: URL ;base64 tests --- fetch/data-urls/resources/data-urls.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index f58ffc80b6688e..24639780784d94 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -100,6 +100,18 @@ ["data:text/plain;a=%2C,X", "data:text/plain;a=,", [88]], + ["data:;base64;base64,WA", + "", + [88]], + ["data:x/x;base64;base64,WA", + "", + [88]], + ["data:x/x;base64;charset=x;base64,WA", + "", + [88]], + ["data:x/x;base64;base64x,WA", + "", + [88]], ["data:;base64,W%20A", "", [88]], @@ -120,5 +132,8 @@ [88]], ["data:;charset=\"x\",X", "text/plain;charset=\"x\"", + [88]], + ["data:;CHARSET=\"X\",X", + "text/plain;CHARSET=\"X\"", [88]] ] From 79defd3d13504522987d1d3ab1f7ea4377e5224d Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 16 Aug 2017 12:19:14 +0200 Subject: [PATCH 04/20] base64: ensure correct character set is used, test example from spec --- fetch/data-urls/resources/base64.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fetch/data-urls/resources/base64.json b/fetch/data-urls/resources/base64.json index 4c7b81d7886327..7de20b28286195 100644 --- a/fetch/data-urls/resources/base64.json +++ b/fetch/data-urls/resources/base64.json @@ -69,5 +69,11 @@ ["AAAA/", null], ["AAA/", [0, 0, 63]], ["\u0000nonsense", null], - ["abcd\u0000nonsense", null] + ["abcd\u0000nonsense", null], + ["YQ", [97]], + ["YR", [97]], + ["~~", null], + ["..", null], + ["--", null], + ["__", null] ] From 7764395cf669d522378d025807cd4c1a5305d07e Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 16 Aug 2017 12:57:25 +0200 Subject: [PATCH 05/20] even more base64 data: URL tests --- fetch/data-urls/resources/data-urls.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index 24639780784d94..d0b2c6f30d37b4 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -127,6 +127,24 @@ ["data:x;base64=x,WA", "", [87, 65]], + ["data:; base64,WA", + "", + [87, 65]], + ["data:;base64 ,WA", + "", + [88]], + ["data:;base 64,WA", + "", + [87, 65]], + ["data:;BASe64,WA", + "", + [88]], + ["data:;%62ase64,WA", + "", + [88]], + ["data:%3Bbase64,WA", + "", + [88]], ["data:;charset=x,X", "text/plain;charset=x", [88]], From a89ff54055535446df022f39d1e438becc9fc0ef Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 17 Aug 2017 18:52:41 +0200 Subject: [PATCH 06/20] fixup --- fetch/data-urls/resources/data-urls.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index d0b2c6f30d37b4..e627ddf2d71093 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -104,13 +104,13 @@ "", [88]], ["data:x/x;base64;base64,WA", - "", + "x/x", [88]], ["data:x/x;base64;charset=x;base64,WA", - "", + "x/x;charset=x", [88]], ["data:x/x;base64;base64x,WA", - "", + "x/x;base64x", [88]], ["data:;base64,W%20A", "", From 64052517b053b8c476a989945af4a8aa3c0695bd Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Mon, 18 Sep 2017 15:19:18 +0200 Subject: [PATCH 07/20] typo --- fetch/data-urls/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fetch/data-urls/README.md b/fetch/data-urls/README.md index 295ccf17493dc8..64c3d7e952156e 100644 --- a/fetch/data-urls/README.md +++ b/fetch/data-urls/README.md @@ -1,6 +1,6 @@ == data: URLs == -`resources/data-urls.json` contains `data:` URL tests. The tests are encoded as a JSON array. Each value in the array is an array of two are three values. The first value describes the input, the second value describes the expected MIME type, null if the input is expected to fail somehow, or the empty string if the expected value is `text/plain;charset=US-ASCII`. The third value, if present, describes the expected body as an array of integers representing bytes. +`resources/data-urls.json` contains `data:` URL tests. The tests are encoded as a JSON array. Each value in the array is an array of two or three values. The first value describes the input, the second value describes the expected MIME type, null if the input is expected to fail somehow, or the empty string if the expected value is `text/plain;charset=US-ASCII`. The third value, if present, describes the expected body as an array of integers representing bytes. These tests are used for `data:` URLs in this directory (see `processing.any.js`). From 3b01a2196379724b59602000594fdfe43d59022c Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 19 Sep 2017 15:15:46 +0200 Subject: [PATCH 08/20] adjust expectations per updates to spec --- fetch/data-urls/resources/data-urls.json | 43 ++++++++++++++---------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index e627ddf2d71093..c22d079a4ae627 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -20,22 +20,22 @@ "text/plain", [88]], ["data:text/plain%20,X", - "text/plain", + "text/plain%20", [88]], ["data:text/plain\f,X", - "text/plain", + "text/plain%0C", [88]], ["data:text/plain%0C,X", - "text/plain", + "text/plain%0C", [88]], ["data:text/plain;,X", - "text/plain;", + "text/plain", [88]], ["data:;x=x;charset=x,X", - "", + "text/plain;x=x;charset=x", [88]], ["data:;x=x,X", - "", + "text/plain;x=x", [88]], ["data:text/plain;charset=windows-1252,%C2%B1", "text/plain;charset=windows-1252", @@ -80,7 +80,7 @@ "", [88]], ["data:†/†,X", - "", + "%E2%80%A0/%E2%80%A0", [88]], ["data:X,X", "", @@ -95,23 +95,23 @@ "unknown/unknown", [88, 32, 88]], ["data:text/plain;a=\",\",X", - "data:text/plain;a=\",\"", - [88]], + "data:text/plain;a=\"", + [34, 44, 88]], ["data:text/plain;a=%2C,X", - "data:text/plain;a=,", + "data:text/plain;a=%2C", [88]], ["data:;base64;base64,WA", - "", + "text/plain;base64", [88]], ["data:x/x;base64;base64,WA", - "x/x", + "x/x;base64", [88]], ["data:x/x;base64;charset=x;base64,WA", - "x/x;charset=x", + "x/x;base64;charset=x", [88]], ["data:x/x;base64;base64x,WA", - "x/x;base64x", - [88]], + "x/x;base64;base64x", + [87, 65]], ["data:;base64,W%20A", "", [88]], @@ -130,6 +130,9 @@ ["data:; base64,WA", "", [87, 65]], + ["data:;base64;,WA", + "", + [87, 65]], ["data:;base64 ,WA", "", [88]], @@ -141,13 +144,19 @@ [88]], ["data:;%62ase64,WA", "", - [88]], + [87, 65]], ["data:%3Bbase64,WA", "", - [88]], + [87, 65]], ["data:;charset=x,X", "text/plain;charset=x", [88]], + ["data:;charset=,X", + "text/plain;charset", + [88]], + ["data:;charset,X", + "text/plain;charset", + [88]], ["data:;charset=\"x\",X", "text/plain;charset=\"x\"", [88]], From d9bf4871a3820246efb5b0e6c9ea322ab005b5f7 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 20 Sep 2017 14:40:23 +0200 Subject: [PATCH 09/20] add more whitespace tests --- fetch/data-urls/resources/data-urls.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index c22d079a4ae627..a0b1df627a32cf 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -151,6 +151,15 @@ ["data:;charset=x,X", "text/plain;charset=x", [88]], + ["data:; charset=x,X", + "text/plain;charset=x", + [88]], + ["data:;charset =x,X", + "text/plain;charset=x", + [88]], + ["data:;charset= x,X", + "text/plain;charset=x", + [88]], ["data:;charset=,X", "text/plain;charset", [88]], From b9c85aa25d1a1e7c8c51b2658e4b56bf5f753437 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Sat, 25 Nov 2017 11:28:53 +0100 Subject: [PATCH 10/20] align with MIME type PR --- fetch/data-urls/resources/data-urls.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index a0b1df627a32cf..141e71c9c79999 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -41,19 +41,19 @@ "text/plain;charset=windows-1252", [194, 177]], ["data:text/plain;Charset=UTF-8,%C2%B1", - "text/plain;Charset=UTF-8", + "text/plain;charset=UTF-8", [194, 177]], ["data:image/gif,%C2%B1", "image/gif", [194, 177]], ["data:IMAGE/gif,%C2%B1", - "IMAGE/gif", + "image/gif", [194, 177]], ["data:IMAGE/gif;hi=x,%C2%B1", - "IMAGE/gif;hi=x", + "image/gif;hi=x", [194, 177]], ["data:IMAGE/gif;CHARSET=x,%C2%B1", - "IMAGE/gif;CHARSET=x", + "image/gif;charset=x", [194, 177]], ["data: ,%FF", "", @@ -158,18 +158,18 @@ "text/plain;charset=x", [88]], ["data:;charset= x,X", - "text/plain;charset=x", + "text/plain;charset= x", [88]], ["data:;charset=,X", - "text/plain;charset", + "text/plain", [88]], ["data:;charset,X", - "text/plain;charset", + "text/plain", [88]], ["data:;charset=\"x\",X", "text/plain;charset=\"x\"", [88]], ["data:;CHARSET=\"X\",X", - "text/plain;CHARSET=\"X\"", + "text/plain;charset=\"X\"", [88]] ] From c6ec1c70033fcaa1106b75f90f3ddd227e317771 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 29 Nov 2017 13:15:39 +0100 Subject: [PATCH 11/20] align with MIME type PR again --- fetch/data-urls/resources/data-urls.json | 32 ++++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index 141e71c9c79999..da87e074381752 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -23,10 +23,10 @@ "text/plain%20", [88]], ["data:text/plain\f,X", - "text/plain%0C", + "text/plain%0c", [88]], ["data:text/plain%0C,X", - "text/plain%0C", + "text/plain%0c", [88]], ["data:text/plain;,X", "text/plain", @@ -80,7 +80,7 @@ "", [88]], ["data:†/†,X", - "%E2%80%A0/%E2%80%A0", + "%e2%80%a0/%e2%80%a0", [88]], ["data:X,X", "", @@ -95,22 +95,22 @@ "unknown/unknown", [88, 32, 88]], ["data:text/plain;a=\",\",X", - "data:text/plain;a=\"", + "data:text/plain;a=\"\\\"\"", [34, 44, 88]], ["data:text/plain;a=%2C,X", "data:text/plain;a=%2C", [88]], ["data:;base64;base64,WA", - "text/plain;base64", + "text/plain", [88]], ["data:x/x;base64;base64,WA", - "x/x;base64", + "x/x", [88]], ["data:x/x;base64;charset=x;base64,WA", - "x/x;base64;charset=x", + "x/x;charset=x", [88]], ["data:x/x;base64;base64x,WA", - "x/x;base64;base64x", + "x/x", [87, 65]], ["data:;base64,W%20A", "", @@ -119,31 +119,31 @@ "", [88]], ["data:x;base64x,WA", - "", + "text/plain", [87, 65]], ["data:x;base64;x,WA", - "", + "text/plain", [88]], ["data:x;base64=x,WA", - "", + "text/plain;base64=x", [87, 65]], ["data:; base64,WA", "", [87, 65]], ["data:;base64;,WA", - "", + "text/plain", [87, 65]], ["data:;base64 ,WA", "", [88]], ["data:;base 64,WA", - "", + "text/plain", [87, 65]], ["data:;BASe64,WA", "", [88]], ["data:;%62ase64,WA", - "", + "text/plain", [87, 65]], ["data:%3Bbase64,WA", "", @@ -155,10 +155,10 @@ "text/plain;charset=x", [88]], ["data:;charset =x,X", - "text/plain;charset=x", + "text/plain", [88]], ["data:;charset= x,X", - "text/plain;charset= x", + "text/plain;charset=\" x\"", [88]], ["data:;charset=,X", "text/plain", From d7d4b71f9d215aa8ff249a01f138ddbd745b9a30 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 8 Dec 2017 10:57:51 +0100 Subject: [PATCH 12/20] address feedback --- fetch/data-urls/resources/data-urls.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index da87e074381752..984efd273c7c97 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -95,10 +95,10 @@ "unknown/unknown", [88, 32, 88]], ["data:text/plain;a=\",\",X", - "data:text/plain;a=\"\\\"\"", + "text/plain;a=\"\\\"\"", [34, 44, 88]], ["data:text/plain;a=%2C,X", - "data:text/plain;a=%2C", + "text/plain;a=%2C", [88]], ["data:;base64;base64,WA", "text/plain", From eef2785b103e4cad54e9de96fd62f9754d6c5f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20J=C3=A4genstedt?= Date: Thu, 4 Jan 2018 14:17:53 +0100 Subject: [PATCH 13/20] test "data:x/x;base64;charset=x,WA" --- fetch/data-urls/resources/data-urls.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index 984efd273c7c97..6dadf8c42a779e 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -106,6 +106,9 @@ ["data:x/x;base64;base64,WA", "x/x", [88]], + ["data:x/x;base64;charset=x,WA", + "x/x;charset=x", + [87, 65]], ["data:x/x;base64;charset=x;base64,WA", "x/x;charset=x", [88]], From 30f58dd68c56abe5a0f219d25f292260455ed072 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 5 Jan 2018 15:55:37 +0100 Subject: [PATCH 14/20] address feedback from Domenic --- fetch/data-urls/resources/data-urls.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index 6dadf8c42a779e..1a12d11f0db5dd 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -170,9 +170,9 @@ "text/plain", [88]], ["data:;charset=\"x\",X", - "text/plain;charset=\"x\"", + "text/plain;charset=x", [88]], ["data:;CHARSET=\"X\",X", - "text/plain;charset=\"X\"", + "text/plain;charset=X", [88]] ] From 8d685a5a6dec12491843532b9a3fcb987bd430fb Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Sun, 7 Jan 2018 08:31:34 +0100 Subject: [PATCH 15/20] address all feedback by Domenic --- fetch/data-urls/resources/data-urls.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index 1a12d11f0db5dd..4ce721befcc2c3 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -95,7 +95,7 @@ "unknown/unknown", [88, 32, 88]], ["data:text/plain;a=\",\",X", - "text/plain;a=\"\\\"\"", + "text/plain", [34, 44, 88]], ["data:text/plain;a=%2C,X", "text/plain;a=%2C", @@ -122,16 +122,16 @@ "", [88]], ["data:x;base64x,WA", - "text/plain", + "", [87, 65]], ["data:x;base64;x,WA", - "text/plain", + "", [88]], ["data:x;base64=x,WA", - "text/plain;base64=x", + "", [87, 65]], ["data:; base64,WA", - "", + "text/plain", [87, 65]], ["data:;base64;,WA", "text/plain", From 17f202dd17d1e7481da6bc50c1ffe1ef535e772d Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 10 Jan 2018 11:37:28 +0100 Subject: [PATCH 16/20] final bug (fingers crossed) --- fetch/data-urls/resources/data-urls.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index 4ce721befcc2c3..59f3c8c4483b2c 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -126,7 +126,7 @@ [87, 65]], ["data:x;base64;x,WA", "", - [88]], + [87, 65]], ["data:x;base64=x,WA", "", [87, 65]], From 8d4335f5dfafc039fe5b75fe412488eb40c29440 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 24 Jan 2018 14:36:08 +0100 Subject: [PATCH 17/20] add some more tests --- fetch/data-urls/resources/data-urls.json | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index 59f3c8c4483b2c..ff2f47454dfb9f 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -131,14 +131,23 @@ "", [87, 65]], ["data:; base64,WA", - "text/plain", - [87, 65]], + "", + [88]], + ["data:; base64,WA", + "", + [88]], + ["data: ;charset=x ; base64,WA", + "text/plain;charset=x", + [88]], ["data:;base64;,WA", "text/plain", [87, 65]], ["data:;base64 ,WA", "", [88]], + ["data:;base64 ,WA", + "", + [88]], ["data:;base 64,WA", "text/plain", [87, 65]], From 7ffe10e43cda770fa2de4f08b4f9e8e61b3a334b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20J=C3=A4genstedt?= Date: Wed, 24 Jan 2018 22:50:48 +0700 Subject: [PATCH 18/20] test "data:text / html,X" (the Safari oddity) --- fetch/data-urls/resources/data-urls.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index ff2f47454dfb9f..e5916071b5a272 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -76,6 +76,9 @@ ["data:text/html ,X", "text/html", [88]], + ["data:text / html,X", + "", + [88]], ["data:†,X", "", [88]], From fdf9418ae203659f7347c9605381bd12e2c6e720 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 25 Jan 2018 14:41:38 +0100 Subject: [PATCH 19/20] add some EOF cases per feedback --- fetch/data-urls/resources/data-urls.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index e5916071b5a272..9dc7210ec4f8fc 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -7,6 +7,15 @@ ["data:,X", "", [88]], + ["data:", + null], + ["data:text/html", + null], + ["data:text/html ;charset=x ", + null], + ["data:,", + "", + []], ["data:,X#X", "", [88]], From 76384324cb1cd3fae54e16103a13c2dd56e986d6 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 30 Jan 2018 18:26:14 +0100 Subject: [PATCH 20/20] flatten --- fetch/data-urls/processing.any.js | 9 ++--- fetch/data-urls/resources/data-urls.json | 50 ++++++++++++------------ 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/fetch/data-urls/processing.any.js b/fetch/data-urls/processing.any.js index 5b8500969763aa..b66a874f45ca30 100644 --- a/fetch/data-urls/processing.any.js +++ b/fetch/data-urls/processing.any.js @@ -1,13 +1,10 @@ promise_test(() => fetch("resources/data-urls.json").then(res => res.json()).then(runDataURLTests), "Setup."); function runDataURLTests(tests) { for(let i = 0; i < tests.length; i++) { - const input = tests[i][0]; - let expectedMimeType = tests[i][1]; - const expectedBody = expectedMimeType !== null ? tests[i][2] : null; + const input = tests[i][0], + expectedMimeType = tests[i][1], + expectedBody = expectedMimeType !== null ? tests[i][2] : null; promise_test(t => { - if(expectedMimeType === "") { - expectedMimeType = "text/plain;charset=US-ASCII"; - } if(expectedMimeType === null) { return promise_rejects(t, new TypeError(), fetch(input)); } else { diff --git a/fetch/data-urls/resources/data-urls.json b/fetch/data-urls/resources/data-urls.json index 9dc7210ec4f8fc..2265b970495883 100644 --- a/fetch/data-urls/resources/data-urls.json +++ b/fetch/data-urls/resources/data-urls.json @@ -1,11 +1,11 @@ [ ["data://test/,X", - "", + "text/plain;charset=US-ASCII", [88]], ["data://test:test/,X", null], ["data:,X", - "", + "text/plain;charset=US-ASCII", [88]], ["data:", null], @@ -14,13 +14,13 @@ ["data:text/html ;charset=x ", null], ["data:,", - "", + "text/plain;charset=US-ASCII", []], ["data:,X#X", - "", + "text/plain;charset=US-ASCII", [88]], ["data:,%FF", - "", + "text/plain;charset=US-ASCII", [255]], ["data:text/plain,X", "text/plain", @@ -65,37 +65,37 @@ "image/gif;charset=x", [194, 177]], ["data: ,%FF", - "", + "text/plain;charset=US-ASCII", [255]], ["data:%20,%FF", - "", + "text/plain;charset=US-ASCII", [255]], ["data:\f,%FF", - "", + "text/plain;charset=US-ASCII", [255]], ["data:%1F,%FF", - "", + "text/plain;charset=US-ASCII", [255]], ["data:\u0000,%FF", - "", + "text/plain;charset=US-ASCII", [255]], ["data:%00,%FF", - "", + "text/plain;charset=US-ASCII", [255]], ["data:text/html ,X", "text/html", [88]], ["data:text / html,X", - "", + "text/plain;charset=US-ASCII", [88]], ["data:†,X", - "", + "text/plain;charset=US-ASCII", [88]], ["data:†/†,X", "%e2%80%a0/%e2%80%a0", [88]], ["data:X,X", - "", + "text/plain;charset=US-ASCII", [88]], ["data:image/png,X X", "image/png", @@ -128,25 +128,25 @@ "x/x", [87, 65]], ["data:;base64,W%20A", - "", + "text/plain;charset=US-ASCII", [88]], ["data:;base64,W%0CA", - "", + "text/plain;charset=US-ASCII", [88]], ["data:x;base64x,WA", - "", + "text/plain;charset=US-ASCII", [87, 65]], ["data:x;base64;x,WA", - "", + "text/plain;charset=US-ASCII", [87, 65]], ["data:x;base64=x,WA", - "", + "text/plain;charset=US-ASCII", [87, 65]], ["data:; base64,WA", - "", + "text/plain;charset=US-ASCII", [88]], ["data:; base64,WA", - "", + "text/plain;charset=US-ASCII", [88]], ["data: ;charset=x ; base64,WA", "text/plain;charset=x", @@ -155,22 +155,22 @@ "text/plain", [87, 65]], ["data:;base64 ,WA", - "", + "text/plain;charset=US-ASCII", [88]], ["data:;base64 ,WA", - "", + "text/plain;charset=US-ASCII", [88]], ["data:;base 64,WA", "text/plain", [87, 65]], ["data:;BASe64,WA", - "", + "text/plain;charset=US-ASCII", [88]], ["data:;%62ase64,WA", "text/plain", [87, 65]], ["data:%3Bbase64,WA", - "", + "text/plain;charset=US-ASCII", [87, 65]], ["data:;charset=x,X", "text/plain;charset=x",