From fd1d2c5ff0563a2acf5a4dbe096cd2f09db652c9 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 19 Oct 2018 13:39:19 +0200 Subject: [PATCH 1/4] MIME types: test 0x0B and 0x0C --- mimesniff/mime-types/README.md | 5 +--- .../mime-types/charset-parameter.window.js | 5 +--- mimesniff/mime-types/parsing.any.js | 5 +--- .../mime-types/resources/mime-charset.py | 17 +++++++++++-- .../mime-types/resources/mime-types.json | 25 +++++++++++++++++++ 5 files changed, 43 insertions(+), 14 deletions(-) diff --git a/mimesniff/mime-types/README.md b/mimesniff/mime-types/README.md index 89e1bf426be66e..3a2681ec74fe69 100644 --- a/mimesniff/mime-types/README.md +++ b/mimesniff/mime-types/README.md @@ -15,14 +15,11 @@ A wrapper for these JSON MIME type tests needs to take care that not all `input` function isByteCompatible(str) { for(let i = 0; i < str.length; i++) { const charCode = str.charCodeAt(i); - // See https://github.com/web-platform-tests/wpt/issues/8372 for 0x0B and 0x0C - // See https://fetch.spec.whatwg.org/#concept-header-value for the remainder + // See https://fetch.spec.whatwg.org/#concept-header-value if(charCode > 0xFF) { return "incompatible"; } else if(charCode === 0x00 || charCode === 0x0A || charCode === 0x0D) { return "header-value-incompatible"; - } else if(charCode === 0x0B || charCode === 0x0C) { - return "wptserve-incompatible"; } } return "compatible"; diff --git a/mimesniff/mime-types/charset-parameter.window.js b/mimesniff/mime-types/charset-parameter.window.js index c288de8349a252..ddac81b74d3b41 100644 --- a/mimesniff/mime-types/charset-parameter.window.js +++ b/mimesniff/mime-types/charset-parameter.window.js @@ -6,14 +6,11 @@ promise_test(() => { function isByteCompatible(str) { for(let i = 0; i < str.length; i++) { const charCode = str.charCodeAt(i); - // See https://github.com/web-platform-tests/wpt/issues/8372 for 0x0B and 0x0C - // See https://fetch.spec.whatwg.org/#concept-header-value for the remainder + // See https://fetch.spec.whatwg.org/#concept-header-value if(charCode > 0xFF) { return "incompatible"; } else if(charCode === 0x00 || charCode === 0x0A || charCode === 0x0D) { return "header-value-incompatible"; - } else if(charCode === 0x0B || charCode === 0x0C) { - return "wptserve-incompatible"; } } return "compatible"; diff --git a/mimesniff/mime-types/parsing.any.js b/mimesniff/mime-types/parsing.any.js index beacada1b10f4b..640a46b9e98ee1 100644 --- a/mimesniff/mime-types/parsing.any.js +++ b/mimesniff/mime-types/parsing.any.js @@ -10,14 +10,11 @@ promise_test(() => { function isByteCompatible(str) { for(let i = 0; i < str.length; i++) { const charCode = str.charCodeAt(i); - // See https://github.com/web-platform-tests/wpt/issues/8372 for 0x0B and 0x0C - // See https://fetch.spec.whatwg.org/#concept-header-value for the remainder + // See https://fetch.spec.whatwg.org/#concept-header-value if(charCode > 0xFF) { return "incompatible"; } else if(charCode === 0x00 || charCode === 0x0A || charCode === 0x0D) { return "header-value-incompatible"; - } else if(charCode === 0x0B || charCode === 0x0C) { - return "wptserve-incompatible"; } } return "compatible"; diff --git a/mimesniff/mime-types/resources/mime-charset.py b/mimesniff/mime-types/resources/mime-charset.py index 433a5bb74b924a..a4f90f52c323fc 100644 --- a/mimesniff/mime-types/resources/mime-charset.py +++ b/mimesniff/mime-types/resources/mime-charset.py @@ -1,3 +1,16 @@ def main(request, response): - response.headers.set("Content-Type", request.GET.first("type")); - response.content = "\n" + content = "\n" + + # This uses the following rather than + # response.headers.set("Content-Type", request.GET.first("type")); + # response.content = content + # to work around https://github.com/web-platform-tests/wpt/issues/8372. + + response.add_required_headers = False + output = "HTTP/1.1 200 OK\r\n" + output += "Content-Length: " + str(len(content)) + "\r\n" + output += "Content-Type: " + request.GET.first("type") + "\r\n" + output += "\r\n" + output += content + response.writer.write(output) + response.close_connection = True diff --git a/mimesniff/mime-types/resources/mime-types.json b/mimesniff/mime-types/resources/mime-types.json index 8918b355bf5a4f..b930c74f534f2e 100644 --- a/mimesniff/mime-types/resources/mime-types.json +++ b/mimesniff/mime-types/resources/mime-types.json @@ -69,6 +69,31 @@ "navigable": true, "encoding": null }, + "0x0B and 0x0C", + { + "input": "text/html;charset=\u000Bgbk", + "output": "text/html", + "navigable": true, + "encoding": "UTF-8" + }, + { + "input": "text/html;charset=\u000Cgbk", + "output": "text/html", + "navigable": true, + "encoding": "UTF-8" + }, + { + "input": "text/html;\u000Bcharset=gbk", + "output": "text/html", + "navigable": true, + "encoding": "UTF-8" + }, + { + "input": "text/html;\u000Ccharset=gbk", + "output": "text/html;charset=gbk", + "navigable": true, + "encoding": "GBK" + }, "Single quotes are a token, not a delimiter", { "input": "text/html;charset='gbk'", From a9ec75f9b5beb83e9ab0ce8ce87b4f41cd10a474 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 30 Oct 2018 13:59:16 +0100 Subject: [PATCH 2/4] don't treat 0x0C as whitespace --- mimesniff/mime-types/resources/mime-types.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mimesniff/mime-types/resources/mime-types.json b/mimesniff/mime-types/resources/mime-types.json index b930c74f534f2e..6980716d782289 100644 --- a/mimesniff/mime-types/resources/mime-types.json +++ b/mimesniff/mime-types/resources/mime-types.json @@ -92,7 +92,7 @@ "input": "text/html;\u000Ccharset=gbk", "output": "text/html;charset=gbk", "navigable": true, - "encoding": "GBK" + "encoding": "UTF-8" }, "Single quotes are a token, not a delimiter", { From 1782ec6102fc2e8018291eeb8751e5af1cb8e7cd Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 2 Nov 2018 09:46:03 +0100 Subject: [PATCH 3/4] oops, thanks Domenic! (still need to figure out the spec here) --- mimesniff/mime-types/resources/mime-types.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mimesniff/mime-types/resources/mime-types.json b/mimesniff/mime-types/resources/mime-types.json index 6980716d782289..d3947101126507 100644 --- a/mimesniff/mime-types/resources/mime-types.json +++ b/mimesniff/mime-types/resources/mime-types.json @@ -74,25 +74,25 @@ "input": "text/html;charset=\u000Bgbk", "output": "text/html", "navigable": true, - "encoding": "UTF-8" + "encoding": null }, { "input": "text/html;charset=\u000Cgbk", "output": "text/html", "navigable": true, - "encoding": "UTF-8" + "encoding": null }, { "input": "text/html;\u000Bcharset=gbk", "output": "text/html", "navigable": true, - "encoding": "UTF-8" + "encoding": null }, { "input": "text/html;\u000Ccharset=gbk", - "output": "text/html;charset=gbk", + "output": "text/html", "navigable": true, - "encoding": "UTF-8" + "encoding": null }, "Single quotes are a token, not a delimiter", { From a6f479dd92a69f43bed299663907d85bade725dd Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Mon, 5 Nov 2018 15:46:18 +0100 Subject: [PATCH 4/4] also test newlines and 0x0B and 0x0C in error conditions --- .../mime-types/resources/mime-types.json | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mimesniff/mime-types/resources/mime-types.json b/mimesniff/mime-types/resources/mime-types.json index d3947101126507..64654b90d5aca0 100644 --- a/mimesniff/mime-types/resources/mime-types.json +++ b/mimesniff/mime-types/resources/mime-types.json @@ -275,6 +275,18 @@ "input": "x/x;x=\t", "output": "x/x" }, + { + "input": "x/x\n\r\t ;x=x", + "output": "x/x;x=x" + }, + { + "input": "\n\r\t x/x;x=x\n\r\t ", + "output": "x/x;x=x" + }, + { + "input": "x/x;\n\r\t x=x\n\r\t ;x=y", + "output": "x/x;x=x" + }, "Latin1", { "input": "text/html;test=\u00FF;charset=gbk", @@ -288,6 +300,22 @@ "output": "x/x;x=x" }, "Failure", + { + "input": "\u000Bx/x", + "output": null + }, + { + "input": "\u000Cx/x", + "output": null + }, + { + "input": "x/x\u000B", + "output": null + }, + { + "input": "x/x\u000C", + "output": null + }, { "input": "", "output": null