Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIME types: test 0x0B and 0x0C #13615

Merged
merged 4 commits into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions mimesniff/mime-types/README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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