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

fix(ext/web): use mimesniff in FileAPI #16233

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
7 changes: 6 additions & 1 deletion ext/web/01_mimesniff.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@
position = res.position;

// 11.8.2.
position++;
const res2 = collectSequenceOfCodepoints(
input,
position,
(c) => c !== "\u003B",
);
position = res2.position;
} else { // 11.9.
// 11.9.1.
const res = collectSequenceOfCodepoints(
Expand Down
10 changes: 3 additions & 7 deletions ext/web/09_file.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@
MathMax,
MathMin,
ObjectPrototypeIsPrototypeOf,
RegExpPrototypeTest,
StringPrototypeCharAt,
StringPrototypeToLowerCase,
StringPrototypeSlice,
Symbol,
SymbolFor,
TypedArrayPrototypeSet,
TypeError,
Uint8Array,
} = window.__bootstrap.primordials;
const mimesniff = window.__bootstrap.mimesniff;
const consoleInternal = window.__bootstrap.console;

// TODO(lucacasonato): this needs to not be hardcoded and instead depend on
Expand Down Expand Up @@ -145,11 +144,8 @@
* @returns {string}
*/
function normalizeType(str) {
let normalizedType = str;
if (!RegExpPrototypeTest(/^[\x20-\x7E]*$/, str)) {
normalizedType = "";
}
return StringPrototypeToLowerCase(normalizedType);
const mime = mimesniff.parseMimeType(str);
return mime !== null ? mimesniff.serializeMimeType(mime) : "";
}

/**
Expand Down
Loading