commit 6063b193214ce6c36548e0cd27ecda14fcd64ead
parent 1cc9a3f60fae799f6bf0cb6d149baa0678759029
Author: Daniel Minor <dminor@mozilla.com>
Date: Wed, 5 Nov 2025 13:16:23 +0000
Bug 1997638 - Check mimetype essence for CSS modules; r=dom-core,smaug
In the initial implementation, I mistakenly checked the mime type, but section
13.7.3 of https://html.spec.whatwg.org/#fetch-a-single-module-script says
this should be the mime type essence.
Differential Revision: https://phabricator.services.mozilla.com/D271091
Diffstat:
3 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp
@@ -8657,9 +8657,13 @@ bool nsContentUtils::IsJsonMimeType(const nsAString& aMimeType) {
return StringEndsWith(subtype, u"+json"_ns);
}
-// https://html.spec.whatwg.org/#fetch-a-single-module-script, 7.3
-bool nsContentUtils::IsCssMimeType(const nsAString& aMimeType) {
- return aMimeType.LowerCaseEqualsLiteral("text/css");
+// https://html.spec.whatwg.org/#fetch-a-single-module-script, 13.7.3
+bool nsContentUtils::HasCssMimeTypeEssence(const nsAString& aMimeType) {
+ nsString contentType, contentCharset;
+ if (MimeType::Parse(aMimeType, contentType, contentCharset)) {
+ return contentType.LowerCaseEqualsLiteral("text/css");
+ }
+ return false;
}
bool nsContentUtils::PrefetchPreloadEnabled(nsIDocShell* aDocShell) {
diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h
@@ -2744,10 +2744,10 @@ class nsContentUtils {
static bool IsJsonMimeType(const nsAString& aMimeType);
/**
- * Returns true if the given MIME type string is a valid CSS MIME type,
+ * Returns true if the given MIME type string has a CSS MIME type essence,
* otherwise false.
*/
- static bool IsCssMimeType(const nsAString& aMimeType);
+ static bool HasCssMimeTypeEssence(const nsAString& aMimeType);
static void SplitMimeType(const nsAString& aValue, nsString& aType,
nsString& aParams);
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp
@@ -4510,7 +4510,7 @@ static bool MimeTypeMatchesExpectedModuleType(
case JS::ModuleType::JSON:
return nsContentUtils::IsJsonMimeType(typeString);
case JS::ModuleType::CSS:
- return nsContentUtils::IsCssMimeType(typeString);
+ return nsContentUtils::HasCssMimeTypeEssence(typeString);
case JS::ModuleType::Unknown:
case JS::ModuleType::Bytes:
break;