@param {string} input
(input)
| 217 | // https://mimesniff.spec.whatwg.org/#parse-a-mime-type |
| 218 | /** @param {string} input */ |
| 219 | function parseMIMEType (input) { |
| 220 | // 1. Remove any leading and trailing HTTP whitespace |
| 221 | // from input. |
| 222 | input = removeHTTPWhitespace(input, true, true) |
| 223 | |
| 224 | // 2. Let position be a position variable for input, |
| 225 | // initially pointing at the start of input. |
| 226 | const position = { position: 0 } |
| 227 | |
| 228 | // 3. Let type be the result of collecting a sequence |
| 229 | // of code points that are not U+002F (/) from |
| 230 | // input, given position. |
| 231 | const type = collectASequenceOfCodePointsFast( |
| 232 | '/', |
| 233 | input, |
| 234 | position |
| 235 | ) |
| 236 | |
| 237 | // 4. If type is the empty string or does not solely |
| 238 | // contain HTTP token code points, then return failure. |
| 239 | // https://mimesniff.spec.whatwg.org/#http-token-code-point |
| 240 | if (type.length === 0 || !HTTP_TOKEN_CODEPOINTS.test(type)) { |
| 241 | return 'failure' |
| 242 | } |
| 243 | |
| 244 | // 5. If position is past the end of input, then return |
| 245 | // failure |
| 246 | if (position.position >= input.length) { |
| 247 | return 'failure' |
| 248 | } |
| 249 | |
| 250 | // 6. Advance position by 1. (This skips past U+002F (/).) |
| 251 | position.position++ |
| 252 | |
| 253 | // 7. Let subtype be the result of collecting a sequence of |
| 254 | // code points that are not U+003B (;) from input, given |
| 255 | // position. |
| 256 | let subtype = collectASequenceOfCodePointsFast( |
| 257 | ';', |
| 258 | input, |
| 259 | position |
| 260 | ) |
| 261 | |
| 262 | // 8. Remove any trailing HTTP whitespace from subtype. |
| 263 | subtype = removeHTTPWhitespace(subtype, false, true) |
| 264 | |
| 265 | // 9. If subtype is the empty string or does not solely |
| 266 | // contain HTTP token code points, then return failure. |
| 267 | if (subtype.length === 0 || !HTTP_TOKEN_CODEPOINTS.test(subtype)) { |
| 268 | return 'failure' |
| 269 | } |
| 270 | |
| 271 | const typeLowercase = type.toLowerCase() |
| 272 | const subtypeLowercase = subtype.toLowerCase() |
| 273 | |
| 274 | // 10. Let mimeType be a new MIME type record whose type |
| 275 | // is type, in ASCII lowercase, and subtype is subtype, |
| 276 | // in ASCII lowercase. |
no test coverage detected