Skip to content

Commit

Permalink
MIME types: test 0x0B, 0x0C, and newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
annevk committed Nov 12, 2018
1 parent 67fe8ce commit 6aeb68e
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 14 deletions.
5 changes: 1 addition & 4 deletions mimesniff/mime-types/README.md
Expand Up @@ -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";
Expand Down
5 changes: 1 addition & 4 deletions mimesniff/mime-types/charset-parameter.window.js
Expand Up @@ -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";
Expand Down
5 changes: 1 addition & 4 deletions mimesniff/mime-types/parsing.any.js
Expand Up @@ -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";
Expand Down
17 changes: 15 additions & 2 deletions 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 = "<meta charset=utf-8>\n<script>document.write(document.characterSet)</script>"
content = "<meta charset=utf-8>\n<script>document.write(document.characterSet)</script>"

# 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
53 changes: 53 additions & 0 deletions mimesniff/mime-types/resources/mime-types.json
Expand Up @@ -69,6 +69,31 @@
"navigable": true,
"encoding": null
},
"0x0B and 0x0C",
{
"input": "text/html;charset=\u000Bgbk",
"output": "text/html",
"navigable": true,
"encoding": null
},
{
"input": "text/html;charset=\u000Cgbk",
"output": "text/html",
"navigable": true,
"encoding": null
},
{
"input": "text/html;\u000Bcharset=gbk",
"output": "text/html",
"navigable": true,
"encoding": null
},
{
"input": "text/html;\u000Ccharset=gbk",
"output": "text/html",
"navigable": true,
"encoding": null
},
"Single quotes are a token, not a delimiter",
{
"input": "text/html;charset='gbk'",
Expand Down Expand Up @@ -250,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",
Expand All @@ -263,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
Expand Down

0 comments on commit 6aeb68e

Please sign in to comment.