Skip to content

Commit 939d171

Browse files
committed
Fix bug parsing normal keyword in font shorthand. Fixes parcel-bundler#42.
1 parent 07c1e79 commit 939d171

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,6 +2937,11 @@ mod tests {
29372937
}
29382938
"#
29392939
});
2940+
2941+
minify_test(".foo { font: normal normal 600 9px/normal Charcoal; }", ".foo{font:600 9px Charcoal}");
2942+
minify_test(".foo { font: normal normal 500 medium/normal Charcoal; }", ".foo{font:500 medium Charcoal}");
2943+
minify_test(".foo { font: normal normal 400 medium Charcoal; }", ".foo{font:400 medium Charcoal}");
2944+
minify_test(".foo { font: normal normal 500 medium/10px Charcoal; }", ".foo{font:500 medium/10px Charcoal}");
29402945
}
29412946

29422947
#[test]

src/properties/font.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,37 +487,51 @@ impl Parse for Font {
487487
let mut stretch = None;
488488
let size;
489489
let mut variant_caps = None;
490+
let mut count = 0;
490491

491492
loop {
493+
// Skip "normal" since it is valid for several properties, but we don't know which ones it will be used for yet.
494+
if input.try_parse(|input| input.expect_ident_matching("normal")).is_ok() {
495+
count += 1;
496+
continue
497+
}
492498
if style.is_none() {
493499
if let Ok(value) = input.try_parse(FontStyle::parse) {
494500
style = Some(value);
501+
count += 1;
495502
continue
496503
}
497504
}
498505
if weight.is_none() {
499506
if let Ok(value) = input.try_parse(FontWeight::parse) {
500507
weight = Some(value);
508+
count += 1;
501509
continue
502510
}
503511
}
504512
if variant_caps.is_none() {
505513
if let Ok(value) = input.try_parse(FontVariantCapsCSS2::parse) {
506514
variant_caps = Some(value);
515+
count += 1;
507516
continue
508517
}
509518
}
510519

511520
if stretch.is_none() {
512521
if let Ok(value) = input.try_parse(FontStretchKeyword::parse) {
513522
stretch = Some(FontStretch::Keyword(value));
523+
count += 1;
514524
continue
515525
}
516526
}
517527
size = Some(FontSize::parse(input)?);
518528
break
519529
}
520530

531+
if count > 4 {
532+
return Err(input.new_custom_error(ParserError::InvalidDeclaration))
533+
}
534+
521535
let size = match size {
522536
Some(s) => s,
523537
None => {

0 commit comments

Comments
 (0)