LibWeb: Create XML document object for SVG-as-image

It's not enough to just use the XML parser, we also have to make sure
the DOM document we produce is an actual XML document.

Fixes #5966
This commit is contained in:
Andreas Kling 2025-08-23 14:02:31 +02:00 committed by Tim Ledbetter
parent 4350bccf8e
commit 3873b1d8cf
3 changed files with 4 additions and 1 deletions

View File

@ -56,7 +56,7 @@ ErrorOr<GC::Ref<SVGDecodedImageData>> SVGDecodedImageData::create(JS::Realm& rea
HTML::UserNavigationInvolvement::None);
// FIXME: Use Navigable::navigate() instead of manually replacing the navigable's document.
auto document = MUST(DOM::Document::create_and_initialize(DOM::Document::Type::HTML, "text/html"_string, navigation_params));
auto document = MUST(DOM::Document::create_and_initialize(DOM::Document::Type::XML, "image/svg+xml"_string, navigation_params));
navigable->set_ongoing_navigation({});
navigable->active_document()->destroy();
navigable->active_session_history_entry()->document_state()->set_document(document);

View File

@ -0,0 +1,2 @@
<!doctype html>
<img src="svg-with-cdata.svg">

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><style><![CDATA[.foo{}]]></style></svg>

After

Width:  |  Height:  |  Size: 127 B