Skip to content

Commit

Permalink
MIME types: test 0x0B and 0x0C
Browse files Browse the repository at this point in the history
  • Loading branch information
annevk committed Oct 19, 2018
1 parent cd57ce9 commit fd1d2c5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
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
25 changes: 25 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": "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'",
Expand Down

0 comments on commit fd1d2c5

Please sign in to comment.