mirror of
https://github.com/typst/typst
synced 2025-05-20 03:55:29 +08:00
Add warning when SVG with foreign object is included (#4932)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
parent
ac982f5856
commit
8501a65566
@ -60,6 +60,13 @@ impl Readable {
|
||||
Readable::Str(v) => v.as_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn as_str(&self) -> Option<&str> {
|
||||
match self {
|
||||
Readable::Str(v) => Some(v.as_str()),
|
||||
Readable::Bytes(v) => std::str::from_utf8(v).ok(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cast! {
|
||||
|
@ -13,7 +13,7 @@ use std::sync::Arc;
|
||||
use comemo::Tracked;
|
||||
use ecow::EcoString;
|
||||
|
||||
use crate::diag::{bail, At, SourceResult, StrResult};
|
||||
use crate::diag::{bail, warning, At, SourceResult, StrResult};
|
||||
use crate::engine::Engine;
|
||||
use crate::foundations::{
|
||||
cast, elem, func, scope, Bytes, Cast, Content, NativeElement, Packed, Show, Smart,
|
||||
@ -190,6 +190,22 @@ fn layout_image(
|
||||
Smart::Auto => determine_format(elem.path().as_str(), data).at(span)?,
|
||||
};
|
||||
|
||||
// Warn the user if the image contains a foreign object. Not perfect
|
||||
// because the svg could also be encoded, but that's an edge case.
|
||||
if format == ImageFormat::Vector(VectorFormat::Svg) {
|
||||
let has_foreign_object =
|
||||
data.as_str().is_some_and(|s| s.contains("<foreignObject"));
|
||||
|
||||
if has_foreign_object {
|
||||
engine.sink.warn(warning!(
|
||||
span,
|
||||
"image contains foreign object";
|
||||
hint: "SVG images with foreign objects might render incorrectly in typst";
|
||||
hint: "see https://github.com/typst/typst/issues/1421 for more information"
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Construct the image itself.
|
||||
let image = Image::with_fonts(
|
||||
data.clone().into(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user