script: display top-level SVG image documents. (#39494)

SVG images served with the image/svg+xml mime type were recognized as
XML documents instead of images, so were not displayed.

Testing: compare the results of `./mach run
https://raw.githubusercontent.com/servo/servo/467821598b59bd84273d91c9d8a33651e10578b8/resources/resource_protocol/servo-color-negative-no-container.svg`

Signed-off-by: webbeef <me@webbeef.org>
This commit is contained in:
webbeef 2025-09-29 02:16:22 -07:00 committed by GitHub
parent 7a7129edd7
commit 47382e0c2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 41 additions and 7 deletions

View file

@ -1000,7 +1000,8 @@ impl ParserContext {
},
// Return the result of loading a media document given navigationParams and type.
MediaType::Image | MediaType::AudioVideo => {
self.load_media_document(parser, media_type, &mime_type)
self.load_media_document(parser, media_type, &mime_type);
return;
},
MediaType::Font => {
let page = format!(

View file

@ -238,10 +238,13 @@ impl MimeClassifier {
}
/// <https://mimesniff.spec.whatwg.org/#xml-mime-type>
/// SVG is worth distinguishing from other XML MIME types:
/// <https://mimesniff.spec.whatwg.org/#mime-type-miscellaneous>
fn is_xml(mt: &Mime) -> bool {
mt.suffix() == Some(mime::XML) ||
mt.essence_str() == "text/xml" ||
mt.essence_str() == "application/xml"
!Self::is_image(mt) &&
(mt.suffix() == Some(mime::XML) ||
mt.essence_str() == "text/xml" ||
mt.essence_str() == "application/xml")
}
/// <https://mimesniff.spec.whatwg.org/#html-mime-type>