aboutsummaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-07-20 13:08:58 -0700
committerGitHub <noreply@github.com>2017-07-20 13:08:58 -0700
commite19fefcb474ea6593a684a1ca4ce616e61188ff0 (patch)
tree000ca7a30d38f6a90694b5b54a61d97a0276ebdf /components
parenteba573d774dd2ac07ec8d62f1ad8deffca4667a4 (diff)
parent5eb0613947a456d4f22900ad260acf3cc5d65014 (diff)
downloadservo-e19fefcb474ea6593a684a1ca4ce616e61188ff0.tar.gz
servo-e19fefcb474ea6593a684a1ca4ce616e61188ff0.zip
Auto merge of #17792 - upsuper:supports-any-value, r=SimonSapin
Fix supports rule parsing issues with <any-value> This eventually fixes #15482, as well as several reftests in mozilla-central which were added for [bug 883987](https://bugzilla.mozilla.org/show_bug.cgi?id=883987). The new function should probably be moved into cssparser crate at some point. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17792) <!-- Reviewable:end -->
Diffstat (limited to 'components')
-rw-r--r--components/style/stylesheets/supports_rule.rs41
1 files changed, 16 insertions, 25 deletions
diff --git a/components/style/stylesheets/supports_rule.rs b/components/style/stylesheets/supports_rule.rs
index ff856bacf3e..5636a55cadc 100644
--- a/components/style/stylesheets/supports_rule.rs
+++ b/components/style/stylesheets/supports_rule.rs
@@ -128,21 +128,18 @@ impl SupportsCondition {
let pos = input.position();
match input.next()? {
Token::ParenthesisBlock => {
- input.parse_nested_block(|input| {
- // `input.try()` not needed here since the alternative uses `consume_all()`.
- parse_condition_or_declaration(input).or_else(|_| {
- consume_all(input);
- Ok(SupportsCondition::FutureSyntax(input.slice_from(pos).to_owned()))
- })
- })
- }
- Token::Function(_) => {
- let result: Result<_, ParseError> = input.parse_nested_block(|i| Ok(consume_all(i)));
- result.unwrap();
- Ok(SupportsCondition::FutureSyntax(input.slice_from(pos).to_owned()))
+ let nested = input.try(|input| {
+ input.parse_nested_block(|i| parse_condition_or_declaration(i))
+ });
+ if nested.is_ok() {
+ return nested;
+ }
}
- t => Err(CssParseError::Basic(BasicParseError::UnexpectedToken(t)))
+ Token::Function(_) => {}
+ t => return Err(CssParseError::Basic(BasicParseError::UnexpectedToken(t))),
}
+ input.parse_nested_block(|i| consume_any_value(i))?;
+ Ok(SupportsCondition::FutureSyntax(input.slice_from(pos).to_owned()))
}
/// Evaluate a supports condition
@@ -235,16 +232,9 @@ impl ToCss for Declaration {
}
}
-/// Slurps up input till exhausted, return string from source position
-fn parse_anything(input: &mut Parser) -> String {
- let pos = input.position();
- consume_all(input);
- input.slice_from(pos).to_owned()
-}
-
-/// Consume input till done
-fn consume_all(input: &mut Parser) {
- while let Ok(_) = input.next() {}
+/// https://drafts.csswg.org/css-syntax-3/#typedef-any-value
+fn consume_any_value<'i, 't>(input: &mut Parser<'i, 't>) -> Result<(), ParseError<'i>> {
+ input.expect_no_error_token().map_err(|err| err.into())
}
impl Declaration {
@@ -252,8 +242,9 @@ impl Declaration {
pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Declaration, ParseError<'i>> {
let prop = input.expect_ident()?.into_owned();
input.expect_colon()?;
- let val = parse_anything(input);
- Ok(Declaration { prop: prop, val: val })
+ let pos = input.position();
+ consume_any_value(input)?;
+ Ok(Declaration { prop: prop, val: input.slice_from(pos).to_owned() })
}
/// Determine if a declaration parses