From: Ian Jackson Date: Mon, 2 May 2022 10:39:44 +0000 (+0100) Subject: svg size handling: Insist on having an SVG element X-Git-Tag: otter-1.1.0~312 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e628a59d9beb3fc2ab438183bc254e00960b899a;p=otter.git svg size handling: Insist on having an SVG element Signed-off-by: Ian Jackson --- 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;