LibWeb/HTML: Support blob URLs in HTMLLinkElement

We are meant to apply the 'URL parser' here, which indicates that
this should work with Blob URLs.
This commit is contained in:
Shannon Booth 2025-01-21 18:03:37 +13:00 committed by Tim Ledbetter
parent d967f56936
commit ef793d8679
Notes: github-actions[bot] 2025-01-21 10:50:40 +00:00
3 changed files with 31 additions and 1 deletions

View file

@ -17,6 +17,7 @@
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h> #include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/ShadowRoot.h> #include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/DOMURL/DOMURL.h>
#include <LibWeb/Fetch/Fetching/Fetching.h> #include <LibWeb/Fetch/Fetching/Fetching.h>
#include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h> #include <LibWeb/Fetch/Infrastructure/FetchAlgorithms.h>
#include <LibWeb/Fetch/Infrastructure/FetchController.h> #include <LibWeb/Fetch/Infrastructure/FetchController.h>
@ -264,7 +265,7 @@ GC::Ptr<Fetch::Infrastructure::Request> HTMLLinkElement::create_link_request(HTM
// 3. Let url be the result of encoding-parsing a URL given options's href, relative to options's base URL. // 3. Let url be the result of encoding-parsing a URL given options's href, relative to options's base URL.
// FIXME: Spec issue: We should be parsing this URL relative to a document or environment settings object. // FIXME: Spec issue: We should be parsing this URL relative to a document or environment settings object.
// https://github.com/whatwg/html/issues/9715 // https://github.com/whatwg/html/issues/9715
auto url = options.base_url.complete_url(options.href); auto url = DOMURL::parse(options.href, options.base_url);
// 4. If url is failure, then return null. // 4. If url is failure, then return null.
if (!url.is_valid()) if (!url.is_valid())

View file

@ -0,0 +1,2 @@
rgb(255, 0, 0)
700

View file

@ -0,0 +1,27 @@
<script src="../include.js"></script>
<div id="test-element">Test Element</div>
<script>
asyncTest((done) => {
const cssContent = `
#test-element {
color: red;
font-weight: bold;
}
`;
const blob = new Blob([cssContent], { type: "text/css" });
const blobURL = URL.createObjectURL(blob);
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = blobURL;
document.head.appendChild(link);
link.onload = () => {
const testElement = document.getElementById('test-element');
const computedStyle = window.getComputedStyle(testElement);
println(computedStyle.color);
println(computedStyle.fontWeight);
done();
};
})
</script>