瀏覽代碼

LibWeb: Don't reject worker scripts with a JavaScript MIME type

The condition for checking if a script has a JS MIME type is currently
flipped. Extract the check to a local to make it a bit easier to reason
about at quick glance.
Timothy Flynn 1 年之前
父節點
當前提交
e1092aed3c
共有 1 個文件被更改,包括 6 次插入2 次删除
  1. 6 2
      Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp

+ 6 - 2
Userland/Libraries/LibWeb/HTML/Scripting/Fetching.cpp

@@ -380,8 +380,12 @@ WebIDL::ExceptionOr<void> fetch_classic_worker_script(AK::URL const& url, Enviro
         // - response's URL's scheme is an HTTP(S) scheme; and
         // - the result of extracting a MIME type from response's header list is not a JavaScript MIME type,
         auto maybe_mime_type = MUST(response->header_list()->extract_mime_type());
-        if (response->url().has_value() && Fetch::Infrastructure::is_http_or_https_scheme(response->url()->scheme()) && (!maybe_mime_type.has_value() || maybe_mime_type->is_javascript())) {
-            dbgln("Invalid non-javascript mime type for worker script at {}", response->url().value());
+        auto mime_type_is_javascript = maybe_mime_type.has_value() && maybe_mime_type->is_javascript();
+
+        if (response->url().has_value() && Fetch::Infrastructure::is_http_or_https_scheme(response->url()->scheme()) && !mime_type_is_javascript) {
+            auto mime_type_serialized = maybe_mime_type.has_value() ? MUST(maybe_mime_type->serialized()) : "unknown"_string;
+            dbgln("Invalid non-javascript mime type \"{}\" for worker script at {}", mime_type_serialized, response->url().value());
+
             // then run onComplete given null, and abort these steps.
             on_complete->function()(nullptr);
             return;