mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 03:25:13 +00:00
LibWeb: Use type attribute to determine HTMLLinkElement
mime type
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Previously, the type attribute was ignored on link elements.
This commit is contained in:
parent
cae0ab2139
commit
a4ee3fb1f0
Notes:
github-actions[bot]
2025-02-21 13:13:27 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/a4ee3fb1f09 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3653
10 changed files with 62 additions and 2 deletions
|
@ -133,6 +133,17 @@ void HTMLLinkElement::attribute_changed(FlyString const& name, Optional<String>
|
|||
{
|
||||
Base::attribute_changed(name, old_value, value, namespace_);
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/semantics.html#processing-the-type-attribute:attr-link-type
|
||||
if (name == HTML::AttributeNames::type) {
|
||||
if (value.has_value())
|
||||
m_mime_type = value->to_ascii_lowercase();
|
||||
else {
|
||||
m_mime_type = {};
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 4.6.7 Link types - https://html.spec.whatwg.org/multipage/links.html#linkTypes
|
||||
auto old_relationship = m_relationship;
|
||||
if (name == HTML::AttributeNames::rel) {
|
||||
|
@ -379,8 +390,14 @@ void HTMLLinkElement::default_fetch_and_process_linked_resource()
|
|||
void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastructure::Response const& response, Variant<Empty, Fetch::Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag, ByteBuffer> body_bytes)
|
||||
{
|
||||
// 1. If the resource's Content-Type metadata is not text/css, then set success to false.
|
||||
auto extracted_mime_type = response.header_list()->extract_mime_type();
|
||||
if (!extracted_mime_type.has_value() || extracted_mime_type->essence() != "text/css") {
|
||||
auto mime_type_string = m_mime_type;
|
||||
if (!mime_type_string.has_value()) {
|
||||
auto extracted_mime_type = response.header_list()->extract_mime_type();
|
||||
if (extracted_mime_type.has_value())
|
||||
mime_type_string = extracted_mime_type->essence();
|
||||
}
|
||||
|
||||
if (mime_type_string != "text/css"sv) {
|
||||
success = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -150,6 +150,8 @@ private:
|
|||
unsigned m_relationship { 0 };
|
||||
// https://html.spec.whatwg.org/multipage/semantics.html#explicitly-enabled
|
||||
bool m_explicitly_enabled { false };
|
||||
|
||||
Optional<String> m_mime_type;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<!DOCTYPE html>
|
||||
<p>You should see a green rectangle below</p>
|
||||
<div style="width:100px;height:100px;background-color:green"></div>
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<style>
|
||||
p:after { font-weight: bold; }
|
||||
p:after { content: "PASS"; color: green; }
|
||||
</style>
|
||||
<p>text/css treated as CSS?
|
||||
<p>TeXt/CsS treated as CSS?
|
||||
<p>text/cſs ignored?
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<link rel=match href=../../../../../../expected/wpt-import/html/semantics/document-metadata/the-link-element/link-type-attribute-ref.html>
|
||||
<link rel="stylesheet" type="application/javascript" href="data:text/css,div { background-color: red !important; }">
|
||||
<link rel="stylesheet" type="ABCtext/css" href="data:text/css,div { background-color: red !important; }">
|
||||
<link rel="stylesheet" type="text/cssDEF" href="data:text/css,div { background-color: red !important; }">
|
||||
<link rel="stylesheet" type="text/invalid" href="data:text/css,div { background-color: red !important; }">
|
||||
<link rel="stylesheet" type="invalid" href="data:text/css,div { background-color: red !important; }">
|
||||
<p>You should see a green rectangle below</p>
|
||||
<div style="width:100px;height:100px;background-color:green"></div>
|
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<link rel="help" href="https://html.spec.whatwg.org/#link-type-stylesheet:process-the-linked-resource">
|
||||
<link rel="help" href="https://html.spec.whatwg.org/#content-type">
|
||||
<link rel="help" href="https://mimesniff.spec.whatwg.org/#mime-type-representation">
|
||||
<link rel="match" href="../../../../../../../expected/wpt-import/html/semantics/links/linktypes/link-type-stylesheet/process-stylesheet-linked-resource-ascii-case-insensitive-ref.html">
|
||||
<meta name="assert" content="link@type values for stylesheet resources are ASCII case-insensitive">
|
||||
<link rel="stylesheet" href="support/process-stylesheet-linked-resource-ascii-case-insensitive.css">
|
||||
<link rel="stylesheet" href="support/process-stylesheet-linked-resource-ascii-case-insensitive-lower.css" type="text/css">
|
||||
<link rel="stylesheet" href="support/process-stylesheet-linked-resource-ascii-case-insensitive-mixed.css" type="TeXt/CsS">
|
||||
<link rel="stylesheet" href="support/process-stylesheet-linked-resource-ascii-case-insensitive-other.css" type="text/cſs">
|
||||
<p id="z-lower">text/css treated as CSS?
|
||||
<p id="z-mixed">TeXt/CsS treated as CSS?
|
||||
<p id="z-other">text/cſs ignored?
|
|
@ -0,0 +1 @@
|
|||
#z-lower:after { content: "PASS"; color: green; }
|
|
@ -0,0 +1 @@
|
|||
#z-mixed:after { content: "PASS"; color: green; }
|
|
@ -0,0 +1 @@
|
|||
#z-other:after { content: "FAIL"; color: red; }
|
|
@ -0,0 +1,3 @@
|
|||
p:after { font-weight: bold; }
|
||||
p:after { content: "FAIL"; color: red; }
|
||||
#z-other:after { content: "PASS"; color: green; }
|
Loading…
Add table
Reference in a new issue