mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-15 22:12:20 +00:00
LibWeb: Fix resolving relative URLs in style sheets
Relative URLs in style sheets should be resolved relative to the style sheet they're in instead of the document.
This commit is contained in:
parent
a37bee919a
commit
1ed5e79478
Notes:
sideshowbarker
2024-07-17 18:46:30 +09:00
Author: https://github.com/skyrising 🔰
Commit: 1ed5e79478
Pull-request: https://github.com/SerenityOS/serenity/pull/13048
4 changed files with 14 additions and 3 deletions
|
@ -77,7 +77,7 @@ void CSSImportRule::resource_did_load()
|
|||
dbgln_if(CSS_LOADER_DEBUG, "CSSImportRule: Resource did load, has encoded data. URL: {}", resource()->url());
|
||||
}
|
||||
|
||||
auto sheet = parse_css(CSS::ParsingContext(*m_document), resource()->encoded_data());
|
||||
auto sheet = parse_css(CSS::ParsingContext(*m_document, resource()->url()), resource()->encoded_data());
|
||||
if (!sheet) {
|
||||
dbgln_if(CSS_LOADER_DEBUG, "CSSImportRule: Failed to parse stylesheet: {}", resource()->url());
|
||||
return;
|
||||
|
|
|
@ -34,13 +34,21 @@ static void log_parse_error(const SourceLocation& location = SourceLocation::cur
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
ParsingContext::ParsingContext(DOM::Document const& document, Optional<AK::URL> const url)
|
||||
: m_document(&document)
|
||||
, m_url(move(url))
|
||||
{
|
||||
}
|
||||
|
||||
ParsingContext::ParsingContext(DOM::Document const& document)
|
||||
: m_document(&document)
|
||||
, m_url(document.url())
|
||||
{
|
||||
}
|
||||
|
||||
ParsingContext::ParsingContext(DOM::ParentNode& parent_node)
|
||||
: m_document(&parent_node.document())
|
||||
, m_url(parent_node.document().url())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -49,9 +57,10 @@ bool ParsingContext::in_quirks_mode() const
|
|||
return m_document ? m_document->in_quirks_mode() : false;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/css-values-4/#relative-urls
|
||||
AK::URL ParsingContext::complete_url(String const& addr) const
|
||||
{
|
||||
return m_document ? m_document->url().complete_url(addr) : AK::URL::create_with_url_or_path(addr);
|
||||
return m_url.has_value() ? m_url->complete_url(addr) : AK::URL::create_with_url_or_path(addr);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -39,6 +39,7 @@ class ParsingContext {
|
|||
public:
|
||||
ParsingContext() = default;
|
||||
explicit ParsingContext(DOM::Document const&);
|
||||
explicit ParsingContext(DOM::Document const&, Optional<AK::URL> const);
|
||||
explicit ParsingContext(DOM::ParentNode&);
|
||||
|
||||
bool in_quirks_mode() const;
|
||||
|
@ -51,6 +52,7 @@ public:
|
|||
private:
|
||||
DOM::Document const* m_document { nullptr };
|
||||
PropertyID m_current_property_id { PropertyID::Invalid };
|
||||
Optional<AK::URL> m_url;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -90,7 +90,7 @@ void HTMLLinkElement::resource_did_load()
|
|||
dbgln_if(CSS_LOADER_DEBUG, "HTMLLinkElement: Resource did load, has encoded data. URL: {}", resource()->url());
|
||||
}
|
||||
|
||||
auto sheet = parse_css(CSS::ParsingContext(document()), resource()->encoded_data());
|
||||
auto sheet = parse_css(CSS::ParsingContext(document(), resource()->url()), resource()->encoded_data());
|
||||
if (!sheet) {
|
||||
dbgln_if(CSS_LOADER_DEBUG, "HTMLLinkElement: Failed to parse stylesheet: {}", resource()->url());
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue