From fd1d2c5ff0563a2acf5a4dbe096cd2f09db652c9 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 19 Oct 2018 13:39:19 +0200 Subject: [PATCH] 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'",