Skip to content

Commit

Permalink
Allow empty string in @-moz-document url-prefix function
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Mar 24, 2022
1 parent 9171b85 commit 6d6c1aa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10134,6 +10134,15 @@ mod tests {
}
}
"#, "@-moz-document url-prefix(){h1{color:#ff0}}");
minify_test(r#"
@-moz-document url-prefix("") {
h1 {
color: yellow;
}
}
"#, "@-moz-document url-prefix(){h1{color:#ff0}}");
error_test("@-moz-document url-prefix(foo) {}", ParserError::UnexpectedToken(crate::properties::custom::Token::Ident("foo".into())));
error_test("@-moz-document url-prefix(\"foo\") {}", ParserError::UnexpectedToken(crate::properties::custom::Token::QuotedString("foo".into())));
}

#[test]
Expand Down
14 changes: 13 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,19 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'i> {
// Firefox only supports the url-prefix() function with no arguments as a legacy CSS hack.
// See https://css-tricks.com/snippets/css/css-hacks-targeting-firefox/
input.expect_function_matching("url-prefix")?;
input.parse_nested_block(|input| input.expect_exhausted().map_err(|e| e.into()))?;
input.parse_nested_block(|input| {
// Firefox also allows an empty string as an argument...
// https://github.com/mozilla/gecko-dev/blob/0077f2248712a1b45bf02f0f866449f663538164/servo/components/style/stylesheets/document_rule.rs#L303
let _ = input.try_parse(|input| -> Result<(), ParseError<'i, Self::Error>> {
let s = input.expect_string()?;
if !s.is_empty() {
return Err(input.new_custom_error(ParserError::InvalidValue))
}
Ok(())
});
input.expect_exhausted()?;
Ok(())
})?;

Ok(AtRulePrelude::MozDocument)
},
Expand Down

0 comments on commit 6d6c1aa

Please sign in to comment.