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. // Return the result of loading a media document given navigationParams and type.
MediaType::Image | MediaType::AudioVideo => { 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 => { MediaType::Font => {
let page = format!( let page = format!(

View file

@ -238,10 +238,13 @@ impl MimeClassifier {
} }
/// <https://mimesniff.spec.whatwg.org/#xml-mime-type> /// <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 { fn is_xml(mt: &Mime) -> bool {
mt.suffix() == Some(mime::XML) || !Self::is_image(mt) &&
(mt.suffix() == Some(mime::XML) ||
mt.essence_str() == "text/xml" || mt.essence_str() == "text/xml" ||
mt.essence_str() == "application/xml" mt.essence_str() == "application/xml")
} }
/// <https://mimesniff.spec.whatwg.org/#html-mime-type> /// <https://mimesniff.spec.whatwg.org/#html-mime-type>

View file

@ -380751,6 +380751,21 @@
] ]
] ]
} }
},
"top-level-document": {
"svg-image-document-svg-xml-mime-type.tentative.html": [
"d5e09d234a4e6de481a43a05f2d8ce0b40af2f5f",
[
null,
[
[
"/svg/top-level-document/svg-image-document-svg-xml-mime-type-ref.html",
"=="
]
],
{}
]
]
} }
}, },
"visual-viewport": { "visual-viewport": {
@ -517989,6 +518004,12 @@
] ]
} }
}, },
"top-level-document": {
"svg-image-document-svg-xml-mime-type-ref.html": [
"ce7462f10d87730479d5488fd9a98a453a342177",
[]
]
},
"types": { "types": {
"helper-SVGElement.ownerSVGElement-02.svg": [ "helper-SVGElement.ownerSVGElement-02.svg": [
"2335bb42c5142ca96a63a4ec457d67ea439638ab", "2335bb42c5142ca96a63a4ec457d67ea439638ab",

View file

@ -1,2 +1,2 @@
[Document-createElement-svg.svg] [Document-createElement-svg.svg]
expected: ERROR expected: TIMEOUT

View file

@ -1,2 +1,2 @@
[parser-uses-create-an-element-for-a-token-svg.svg] [parser-uses-create-an-element-for-a-token-svg.svg]
expected: ERROR expected: TIMEOUT

View file

@ -1,2 +1,2 @@
[user-interaction-editing-designMode-svg.svg] [user-interaction-editing-designMode-svg.svg]
expected: ERROR expected: TIMEOUT

View file

@ -0,0 +1,3 @@
<!doctype html>
<meta charset="utf-8">
<iframe src="../shapes/circle-01.svg?pipe=header(Content-Type,image/svg)">

View file

@ -0,0 +1,6 @@
<!doctype html>
<meta charset="utf-8">
<title>Display image/svg+xml top level documents</title>
<link rel='match' href='svg-image-document-svg-xml-mime-type-ref.html'>
<link rel="author" title="webbeef" href="mailto:me@webbeef.org">
<iframe src="../shapes/circle-01.svg?pipe=header(Content-Type,image/svg+xml)">