Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix parsing bugs in grid-gap and grid-line
  • Loading branch information
wafflespeanut committed May 23, 2017
1 parent 9468fae commit 7dbd17b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions components/style/properties/longhand/position.mako.rs
Expand Up @@ -223,6 +223,7 @@ ${helpers.predefined_type("object-position",
${helpers.predefined_type("grid-%s-gap" % kind,
"LengthOrPercentage",
"computed::LengthOrPercentage::Length(Au(0))",
"parse_non_negative",
spec="https://drafts.csswg.org/css-grid/#propdef-grid-%s-gap" % kind,
animation_value_type="ComputedValue",
products="gecko")}
Expand Down
24 changes: 19 additions & 5 deletions components/style/values/generics/grid.rs
Expand Up @@ -76,21 +76,35 @@ impl Parse for GridLine {
return Ok(grid_line)
}

// <custom-ident> | [ <integer> && <custom-ident>? ] | [ span && [ <integer> || <custom-ident> ] ]
// This <grid-line> horror is simply,
// [ span? && [ <custom-ident> || <integer> ] ]
// And, for some magical reason, "span" should be the first or last value and not in-between.
let mut val_before_span = false;

for _ in 0..3 { // Maximum possible entities for <grid-line>
if input.try(|i| i.expect_ident_matching("span")).is_ok() {
if grid_line.is_span || grid_line.line_num.is_some() || grid_line.ident.is_some() {
return Err(()) // span (if specified) should be first
if grid_line.is_span {
return Err(())
}

if grid_line.line_num.is_some() || grid_line.ident.is_some() {
val_before_span = true;
}
grid_line.is_span = true; // span (if specified) should be first

grid_line.is_span = true;
} else if let Ok(i) = input.try(|i| Integer::parse(context, i)) {
if i.value() == 0 || grid_line.line_num.is_some() {
if i.value() == 0 || val_before_span || grid_line.line_num.is_some() {
return Err(())
}

grid_line.line_num = Some(i);
} else if let Ok(name) = input.try(|i| i.expect_ident()) {
if grid_line.ident.is_some() || CustomIdent::from_ident((&*name).into(), &[]).is_err() {
if val_before_span || grid_line.ident.is_some() ||
CustomIdent::from_ident((&*name).into(), &[]).is_err() {
return Err(())
}

grid_line.ident = Some(name.into_owned());
} else {
break
Expand Down

0 comments on commit 7dbd17b

Please sign in to comment.