mirror of
https://github.com/servo/servo.git
synced 2025-06-21 07:38:59 +01:00
Check rule-level @counter-style validity
This commit is contained in:
parent
6dc317f80b
commit
331acfaf9b
1 changed files with 38 additions and 1 deletions
|
@ -28,6 +28,7 @@ pub fn parse_counter_style_name(input: &mut Parser) -> Result<CustomIdent, ()> {
|
||||||
/// Parse the body (inside `{}`) of an @counter-style rule
|
/// Parse the body (inside `{}`) of an @counter-style rule
|
||||||
pub fn parse_counter_style_body(name: CustomIdent, context: &ParserContext, input: &mut Parser)
|
pub fn parse_counter_style_body(name: CustomIdent, context: &ParserContext, input: &mut Parser)
|
||||||
-> Result<CounterStyleRule, ()> {
|
-> Result<CounterStyleRule, ()> {
|
||||||
|
let start = input.position();
|
||||||
let mut rule = CounterStyleRule::empty(name);
|
let mut rule = CounterStyleRule::empty(name);
|
||||||
{
|
{
|
||||||
let parser = CounterStyleRuleParser {
|
let parser = CounterStyleRuleParser {
|
||||||
|
@ -44,8 +45,44 @@ pub fn parse_counter_style_body(name: CustomIdent, context: &ParserContext, inpu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let error = match *rule.system() {
|
||||||
|
ref system @ System::Cyclic |
|
||||||
|
ref system @ System::Fixed { .. } |
|
||||||
|
ref system @ System::Symbolic |
|
||||||
|
ref system @ System::Alphabetic |
|
||||||
|
ref system @ System::Numeric
|
||||||
|
if rule.symbols.is_none() => {
|
||||||
|
let system = system.to_css_string();
|
||||||
|
Some(format!("Invalid @counter-style rule: 'system: {}' without 'symbols'", system))
|
||||||
|
}
|
||||||
|
ref system @ System::Alphabetic |
|
||||||
|
ref system @ System::Numeric
|
||||||
|
if rule.symbols().unwrap().0.len() < 2 => {
|
||||||
|
let system = system.to_css_string();
|
||||||
|
Some(format!("Invalid @counter-style rule: 'system: {}' less than two 'symbols'",
|
||||||
|
system))
|
||||||
|
}
|
||||||
|
System::Additive if rule.additive_symbols.is_none() => {
|
||||||
|
let s = "Invalid @counter-style rule: 'system: additive' without 'additive-symbols'";
|
||||||
|
Some(s.to_owned())
|
||||||
|
}
|
||||||
|
System::Extends(_) if rule.symbols.is_some() => {
|
||||||
|
let s = "Invalid @counter-style rule: 'system: extends …' with 'symbols'";
|
||||||
|
Some(s.to_owned())
|
||||||
|
}
|
||||||
|
System::Extends(_) if rule.additive_symbols.is_some() => {
|
||||||
|
let s = "Invalid @counter-style rule: 'system: extends …' with 'additive-symbols'";
|
||||||
|
Some(s.to_owned())
|
||||||
|
}
|
||||||
|
_ => None
|
||||||
|
};
|
||||||
|
if let Some(message) = error {
|
||||||
|
log_css_error(input, start, &message, context);
|
||||||
|
Err(())
|
||||||
|
} else {
|
||||||
Ok(rule)
|
Ok(rule)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct CounterStyleRuleParser<'a, 'b: 'a> {
|
struct CounterStyleRuleParser<'a, 'b: 'a> {
|
||||||
context: &'a ParserContext<'b>,
|
context: &'a ParserContext<'b>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue