From 72f69b8c278b5da6d8ccc305a3d231a133876853 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Tue, 20 Nov 2018 18:26:15 -0500 Subject: [PATCH] Spec update: use HTTP whitespace instead of ASCII whitespace Follows https://github.com/whatwg/mimesniff/pull/90. --- README.md | 2 +- lib/parser.js | 14 +++++++------- lib/utils.js | 12 ++++++------ scripts/get-latest-platform-tests.js | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a0ecd15..f9cef41 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/parser.js b/lib/parser.js index af77628..bbc9c65 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -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 = ""; @@ -35,7 +35,7 @@ module.exports = input => { ++position; } - subtype = removeTrailingASCIIWhitespace(subtype); + subtype = removeTrailingHTTPWhitespace(subtype); if (subtype.length === 0 || !solelyContainsHTTPTokenCodePoints(subtype)) { return null; @@ -51,7 +51,7 @@ module.exports = input => { // Skip past ";" ++position; - while (isASCIIWhitespaceChar(input[position])) { + while (isHTTPWhitespaceChar(input[position])) { ++position; } @@ -105,7 +105,7 @@ module.exports = input => { ++position; } - parameterValue = removeTrailingASCIIWhitespace(parameterValue); + parameterValue = removeTrailingHTTPWhitespace(parameterValue); if (parameterValue === "") { continue; diff --git a/lib/utils.js b/lib/utils.js index 95ffd2d..80e28e5 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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 => { diff --git a/scripts/get-latest-platform-tests.js b/scripts/get-latest-platform-tests.js index ebec815..f5dbd30 100644 --- a/scripts/get-latest-platform-tests.js +++ b/scripts/get-latest-platform-tests.js @@ -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/`;