Skip to content

Commit

Permalink
LibWeb: Resolve SVGImageElement source URL correctly
Browse files Browse the repository at this point in the history
This fixes an issue where an SVGImageElement, whose source was a
relative URL would not load inside an iframe.
  • Loading branch information
tcl3 authored and kalenikaliaksandr committed Jan 19, 2025
1 parent b7512de commit 400aefb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Libraries/LibWeb/SVG/SVGImageElement.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Tim Ledbetter <[email protected]>
* Copyright (c) 2024-2025, Tim Ledbetter <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
Expand Down Expand Up @@ -140,7 +140,13 @@ Gfx::Rect<CSSPixels> SVGImageElement::bounding_box() const
// https://www.w3.org/TR/SVG2/linking.html#processingURL
void SVGImageElement::process_the_url(Optional<String> const& href)
{
m_href = document().url().complete_url(href.value_or(String {}));
if (!href.has_value()) {
m_href = {};
return;
}

m_href = document().parse_url(*href);

if (!m_href.is_valid())
return;

Expand Down
2 changes: 2 additions & 0 deletions Tests/LibWeb/Ref/expected/svg-image-in-iframe-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<iframe srcdoc="<svg xmlns='http://www.w3.org/2000/svg'><rect width='150' height='100' fill='green' /></svg>"></iframe>
3 changes: 3 additions & 0 deletions Tests/LibWeb/Ref/input/svg-image-in-iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!DOCTYPE html>
<link rel="match" href="../expected/svg-image-in-iframe-ref.html" />
<iframe srcdoc="<svg xmlns='http://www.w3.org/2000/svg'><image href='../data/rectangle.png' width='150' height='100' /></svg>"></iframe>

0 comments on commit 400aefb

Please sign in to comment.