From f587a363670afd4c6a803f161aadf14cb7c2ff83 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Wed, 29 Jul 2020 08:27:53 -0400 Subject: [PATCH] fix regression involving `min` and `max` inside color functions --- src/parse/args.rs | 4 ++-- src/parse/value/css_function.rs | 2 ++ src/parse/value/parse.rs | 19 ++----------------- tests/color.rs | 6 ++++++ 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/parse/args.rs b/src/parse/args.rs index 3732201..2702b0e 100644 --- a/src/parse/args.rs +++ b/src/parse/args.rs @@ -345,9 +345,9 @@ impl<'a> Parser<'a> { None => return Err(("expected \")\".", span).into()), } } - Some(..) => { + Some(c) => { value?; - unreachable!() + unreachable!("{:?}", c) } None => return Err(("expected \")\".", span).into()), } diff --git a/src/parse/value/css_function.rs b/src/parse/value/css_function.rs index e3f2674..c74bd15 100644 --- a/src/parse/value/css_function.rs +++ b/src/parse/value/css_function.rs @@ -240,6 +240,8 @@ impl<'a> Parser<'a> { ')' => { self.toks.advance_cursor(); buf.push(')'); + // todo: https://github.com/foresterre/peekmore/issues/38 + self.toks.peek(); return Ok(Some(buf)); } '+' | '-' | '*' | '/' => { diff --git a/src/parse/value/parse.rs b/src/parse/value/parse.rs index aac95bc..f1483cb 100644 --- a/src/parse/value/parse.rs +++ b/src/parse/value/parse.rs @@ -268,25 +268,10 @@ impl<'a> Parser<'a> { if let Some(Token { kind: '(', .. }) = self.toks.peek() { self.toks.next(); - if lower == "min" { - match self.try_parse_min_max("min", true)? { + if lower == "min" || lower == "max" { + match self.try_parse_min_max(&lower, true)? { Some(val) => { self.toks.truncate_iterator_to_cursor(); - self.toks.next(); - return Ok(IntermediateValue::Value(HigherIntermediateValue::Literal( - Value::String(val, QuoteKind::None), - )) - .span(span)); - } - None => { - self.toks.reset_cursor(); - } - } - } else if lower == "max" { - match self.try_parse_min_max("max", true)? { - Some(val) => { - self.toks.truncate_iterator_to_cursor(); - self.toks.next(); return Ok(IntermediateValue::Value(HigherIntermediateValue::Literal( Value::String(val, QuoteKind::None), )) diff --git a/tests/color.rs b/tests/color.rs index 0afa92a..3fa4968 100644 --- a/tests/color.rs +++ b/tests/color.rs @@ -674,3 +674,9 @@ error!( alpha_filter_invalid_non_alphabetic_start, "a {\n color: alpha(1=a);\n}\n", "Error: $color: 1=a is not a color." ); +// todo: we need many more of these tests +test!( + rgba_special_fn_4th_arg_max, + "a {\n color: rgba(1 2 max(3, 3));\n}\n", + "a {\n color: rgba(1, 2, max(3, 3));\n}\n" +);