From e628a59d9beb3fc2ab438183bc254e00960b899a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 2 May 2022 11:39:44 +0100 Subject: [PATCH] svg size handling: Insist on having an SVG element Signed-off-by: Ian Jackson --- src/utils.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils.rs b/src/utils.rs index c0968f58..a37839b9 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -220,12 +220,14 @@ pub enum SVGSizeError { #[error("attribute {0} repeated")] AttributeRepeated(String), #[error("attribute {0} unparseable")] AttributeUnparseable(String), #[error("specifies only one of width and height")] OneOfWidthHeight, + #[error("encountered EOF before SVG element")] UnexpectedEOF, } #[throws(SVGSizeError)] pub fn svg_parse_size(xml: &str) -> Option> { let mut tokens = xmlparser::Tokenizer::from(xml) - .map(|t| t.map_err(|e| SvSE::ParseError(e.to_string()))); + .map(|t| t.map_err(|e| SvSE::ParseError(e.to_string()))) + .chain(iter::repeat_with(|| Err(SvSE::UnexpectedEOF))); use xmlparser::Token as Tk; let mut in_svg_element = false; -- 2.30.2