diff --git a/src/value/mod.rs b/src/value/mod.rs index f24ed4f..716e71a 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -82,11 +82,11 @@ fn visit_quoted_string(buf: &mut String, force_double_quote: bool, string: &str) buffer.push(hex_char_for(c as u32 >> 4)) } buffer.push(hex_char_for(c as u32 & 0xF)); - if iter.peek().is_none() { - break; - } - let next = iter.peek().unwrap(); + let next = match iter.peek() { + Some(v) => v, + None => break, + }; if next.is_ascii_hexdigit() || next == &' ' || next == &'\t' { buffer.push(' '); @@ -148,7 +148,7 @@ impl Value { Self::List(vals, sep, brackets) => match brackets { Brackets::None => Cow::owned( vals.iter() - .filter(|x| !x.is_null(span).unwrap()) + .filter(|x| !x.clone().is_null(span).unwrap_or(false)) .map(|x| x.to_css_string(span)) .collect::>>>()? .join(sep.as_str()), @@ -156,7 +156,7 @@ impl Value { Brackets::Bracketed => Cow::owned(format!( "[{}]", vals.iter() - .filter(|x| !x.is_null(span).unwrap()) + .filter(|x| !x.is_null(span).unwrap_or(false)) .map(|x| x.to_css_string(span)) .collect::>>>()? .join(sep.as_str()), @@ -199,7 +199,7 @@ impl Value { Self::Null => Cow::const_str(""), Self::ArgList(args) => Cow::owned( args.iter() - .filter(|x| !x.is_null(span).unwrap()) + .filter(|x| !x.is_null(span).unwrap_or(false)) .map(|a| Ok(a.node.to_css_string(span)?)) .collect::>>>()? .join(", "), diff --git a/tests/list.rs b/tests/list.rs index e68c5ae..a396edd 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -314,3 +314,19 @@ test!( "a {\n color: 3;\n}\n" ); test!(empty_bracketed_list, "a {\n empty: [];\n}\n"); +error!( + invalid_item_in_space_separated_list, + "a {\n color: red color * #abc;\n}\n", "Error: Undefined operation \"color * #abc\"." +); +error!( + invalid_item_in_comma_separated_list, + "a {\n color: red, color * #abc;\n}\n", "Error: Undefined operation \"color * #abc\"." +); +error!( + invalid_item_in_space_separated_list_inside_interpolation, + "a {\n color: #{red color * #abc};\n}\n", "Error: Undefined operation \"color * #abc\"." +); +error!( + invalid_item_in_comma_separated_list_inside_interpolation, + "a {\n color: #{red, color * #abc};\n}\n", "Error: Undefined operation \"color * #abc\"." +);