Skip to content

Commit

Permalink
Spec update: use HTTP whitespace instead of ASCII whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Nov 20, 2018
1 parent 426bf68 commit 72f69b8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ console.assert(mimeType.isXML() === false);

Parsing is a fairly complex process; see [the specification](https://mimesniff.spec.whatwg.org/#parsing-a-mime-type) for details (and similarly [for serialization](https://mimesniff.spec.whatwg.org/#serializing-a-mime-type)).

This package's algorithms conform to those of the WHATWG [MIME Sniffing Standard](https://mimesniff.spec.whatwg.org/), and is aligned up to commit [190c18a](https://github.com/whatwg/mimesniff/commit/190c18af1d81754ff298cfb6fc9e581afdce4d2c).
This package's algorithms conform to those of the WHATWG [MIME Sniffing Standard](https://mimesniff.spec.whatwg.org/), and is aligned up to commit [126286a](https://github.com/whatwg/mimesniff/commit/126286ab2dcf3e2d541349ed93539a88bf394ad5).

## `MIMEType` API

Expand Down
14 changes: 7 additions & 7 deletions lib/parser.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"use strict";
const {
removeLeadingAndTrailingASCIIWhitespace,
removeTrailingASCIIWhitespace,
isASCIIWhitespaceChar,
removeLeadingAndTrailingHTTPWhitespace,
removeTrailingHTTPWhitespace,
isHTTPWhitespaceChar,
solelyContainsHTTPTokenCodePoints,
soleyContainsHTTPQuotedStringTokenCodePoints,
asciiLowercase
} = require("./utils.js");

module.exports = input => {
input = removeLeadingAndTrailingASCIIWhitespace(input);
input = removeLeadingAndTrailingHTTPWhitespace(input);

let position = 0;
let type = "";
Expand All @@ -35,7 +35,7 @@ module.exports = input => {
++position;
}

subtype = removeTrailingASCIIWhitespace(subtype);
subtype = removeTrailingHTTPWhitespace(subtype);

if (subtype.length === 0 || !solelyContainsHTTPTokenCodePoints(subtype)) {
return null;
Expand All @@ -51,7 +51,7 @@ module.exports = input => {
// Skip past ";"
++position;

while (isASCIIWhitespaceChar(input[position])) {
while (isHTTPWhitespaceChar(input[position])) {
++position;
}

Expand Down Expand Up @@ -105,7 +105,7 @@ module.exports = input => {
++position;
}

parameterValue = removeTrailingASCIIWhitespace(parameterValue);
parameterValue = removeTrailingHTTPWhitespace(parameterValue);

if (parameterValue === "") {
continue;
Expand Down
12 changes: 6 additions & 6 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"use strict";

exports.removeLeadingAndTrailingASCIIWhitespace = string => {
return string.replace(/^[ \t\n\f\r]+/, "").replace(/[ \t\n\f\r]+$/, "");
exports.removeLeadingAndTrailingHTTPWhitespace = string => {
return string.replace(/^[ \t\n\r]+/, "").replace(/[ \t\n\r]+$/, "");
};

exports.removeTrailingASCIIWhitespace = string => {
return string.replace(/[ \t\n\f\r]+$/, "");
exports.removeTrailingHTTPWhitespace = string => {
return string.replace(/[ \t\n\r]+$/, "");
};

exports.isASCIIWhitespaceChar = char => {
return char === " " || char === "\t" || char === "\n" || char === "\f" || char === "\r";
exports.isHTTPWhitespaceChar = char => {
return char === " " || char === "\t" || char === "\n" || char === "\r";
};

exports.solelyContainsHTTPTokenCodePoints = string => {
Expand Down
2 changes: 1 addition & 1 deletion scripts/get-latest-platform-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ process.on("unhandledRejection", err => {
// 1. Go to https://github.com/w3c/web-platform-tests/tree/master/mimesniff
// 2. Press "y" on your keyboard to get a permalink
// 3. Copy the commit hash
const commitHash = "3600cbb1ecf8ae1b0521a3d4f5fd5480d0bc0f1f";
const commitHash = "e340f910d3652a059fde65ac0d026df1a003a7be";

const urlPrefix = `https://raw.githubusercontent.com/w3c/web-platform-tests/${commitHash}` +
`/mimesniff/mime-types/resources/`;
Expand Down

0 comments on commit 72f69b8

Please sign in to comment.