remove unwraps in Value::to_css_string

This commit is contained in:
ConnorSkees 2020-06-18 01:08:30 -04:00
parent 5d5e7adb98
commit d90ef7fa41
2 changed files with 23 additions and 7 deletions

View File

@ -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::<SassResult<Vec<Cow<'static, str>>>>()?
.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::<SassResult<Vec<Cow<'static, str>>>>()?
.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::<SassResult<Vec<Cow<'static, str>>>>()?
.join(", "),

View File

@ -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\"."
);