From 8e060950d552b2b3f4a2194da847d606578b166c Mon Sep 17 00:00:00 2001 From: Midas Lambrichts Date: Tue, 25 Aug 2020 01:35:55 +0200 Subject: [PATCH] Fix panic when progid is the last token by removing unwrap (#39) * Fix panic when progid by removing unwrap * Incorporate PR feedback --- src/parse/value/css_function.rs | 7 ++++++- tests/special-functions.rs | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/parse/value/css_function.rs b/src/parse/value/css_function.rs index b900685..c20b0c3 100644 --- a/src/parse/value/css_function.rs +++ b/src/parse/value/css_function.rs @@ -64,7 +64,12 @@ impl<'a> Parser<'a> { pub(super) fn parse_progid(&mut self) -> SassResult { let mut string = String::new(); - let mut span = self.toks.peek().unwrap().pos(); + let mut span = match self.toks.peek() { + Some(token) => token.pos(), + None => { + return Err(("expected \"(\".", self.span_before).into()); + } + }; while let Some(tok) = self.toks.next() { span = span.merge(tok.pos()); match tok.kind { diff --git a/tests/special-functions.rs b/tests/special-functions.rs index b3ed40b..6db0887 100644 --- a/tests/special-functions.rs +++ b/tests/special-functions.rs @@ -202,3 +202,7 @@ test!( "a {\n color: PrOgId:foo(fff);\n}\n", "a {\n color: progid:foo(fff);\n}\n" ); +error!( + progid_nothing_after, + "a { color: progid:", "Error: expected \"(\"." +);