From 03c8f41868e21cdf75fea3a00a3b060fe7249b03 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 13 May 2020 20:02:21 -0500 Subject: [PATCH] Remove three unwraps from escaped_char --- src/parser/strings.rs | 30 +++++++++++++++--------------- tests/fuzz_cases.rs | 10 ++++++++++ 2 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 tests/fuzz_cases.rs diff --git a/src/parser/strings.rs b/src/parser/strings.rs index bd2d42a5e..21aa611e7 100644 --- a/src/parser/strings.rs +++ b/src/parser/strings.rs @@ -315,22 +315,22 @@ fn escaped_char(input: &[u8]) -> IResult<&[u8], char> { tag("\\"), alt(( value('\\', tag("\\")), - map( - terminated( - recognize(many_m_n( - 1, - 6, - one_of("0123456789ABCDEFabcdef"), - )), - opt(tag(" ")), + map_opt( + map_res( + map_res( + terminated( + recognize(many_m_n( + 1, + 6, + one_of("0123456789ABCDEFabcdef"), + )), + opt(tag(" ")), + ), + input_to_str, + ), + |s| u32::from_str_radix(s, 16), ), - |hp| { - std::char::from_u32( - u32::from_str_radix(input_to_str(hp).unwrap(), 16) - .unwrap(), - ) - .unwrap() - }, + std::char::from_u32 ), take_char, )), diff --git a/tests/fuzz_cases.rs b/tests/fuzz_cases.rs new file mode 100644 index 000000000..2e179463c --- /dev/null +++ b/tests/fuzz_cases.rs @@ -0,0 +1,10 @@ +use rsass::{compile_scss, output}; + +#[test] +fn bad_escape() { + let format = output::Format { + style: output::Style::Compressed, + precision: 5, + }; + assert!(compile_scss(b"\\d00000", format).is_err()); +}