Fix panic when parsing invalid gradiant

Fixes #3241
This commit is contained in:
Olivier Goffart 2023-08-09 19:18:20 +02:00 committed by Olivier Goffart
parent 94ba420c01
commit a310fdc912
2 changed files with 6 additions and 1 deletions

View file

@ -486,7 +486,10 @@ impl Expression {
rest.iter().position(|s| !matches!(s.1, Expression::Invalid)).unwrap_or(rest.len());
if pos > 0 && pos < rest.len() {
let (middle, after) = rest.split_at_mut(pos);
let begin = &before.last().expect("The first should never be invalid").1;
let begin = before
.last()
.map(|s| &s.1)
.unwrap_or(&Expression::NumberLiteral(1., Unit::None));
let end = &after.first().expect("The last should never be invalid").1;
for (i, (_, e)) in middle.iter_mut().enumerate() {
debug_assert!(matches!(e, Expression::Invalid));

View file

@ -27,4 +27,6 @@ export X := Rectangle {
property<brush> g14: @linear-gradient(-128deg, white, blue r);
// ^error{Unknown unqualified identifier 'r'}
property <brush> g15: @linear-gradient(90deg, brown o, green); // #3241
// ^error{Unknown unqualified identifier 'o'}
}