mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #16142 - emilio:dumbness, r=canaltinova
style: Make PercentageOrNumber also reject negative percentages. It always returns true, so this is just stupid. <!-- 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/16142) <!-- Reviewable:end -->
This commit is contained in:
commit
7b64c3c419
2 changed files with 22 additions and 12 deletions
|
@ -909,15 +909,26 @@ impl ToCss for Percentage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Percentage {
|
||||||
|
fn parse_internal(input: &mut Parser, context: AllowedNumericType) -> Result<Self, ()> {
|
||||||
|
match try!(input.next()) {
|
||||||
|
Token::Percentage(ref value) if context.is_ok(value.unit_value) => {
|
||||||
|
Ok(Percentage(value.unit_value))
|
||||||
|
}
|
||||||
|
_ => Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parses a percentage token, but rejects it if it's negative.
|
||||||
|
pub fn parse_non_negative(input: &mut Parser) -> Result<Self, ()> {
|
||||||
|
Self::parse_internal(input, AllowedNumericType::NonNegative)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Parse for Percentage {
|
impl Parse for Percentage {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||||
let context = AllowedNumericType::All;
|
Self::parse_internal(input, AllowedNumericType::All)
|
||||||
match try!(input.next()) {
|
|
||||||
Token::Percentage(ref value) if context.is_ok(value.unit_value) =>
|
|
||||||
Ok(Percentage(value.unit_value)),
|
|
||||||
_ => Err(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -538,8 +538,8 @@ impl Parse for Number {
|
||||||
impl Number {
|
impl Number {
|
||||||
fn parse_with_minimum(input: &mut Parser, min: CSSFloat) -> Result<Number, ()> {
|
fn parse_with_minimum(input: &mut Parser, min: CSSFloat) -> Result<Number, ()> {
|
||||||
match parse_number(input) {
|
match parse_number(input) {
|
||||||
Ok(value) if value < min => Err(()),
|
Ok(value) if value >= min => Ok(Number(value)),
|
||||||
value => value.map(Number),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,13 +585,12 @@ pub enum NumberOrPercentage {
|
||||||
no_viewport_percentage!(NumberOrPercentage);
|
no_viewport_percentage!(NumberOrPercentage);
|
||||||
|
|
||||||
impl Parse for NumberOrPercentage {
|
impl Parse for NumberOrPercentage {
|
||||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||||
if let Ok(per) = input.try(|input| Percentage::parse(context, input)) {
|
if let Ok(per) = input.try(Percentage::parse_non_negative) {
|
||||||
return Ok(NumberOrPercentage::Percentage(per));
|
return Ok(NumberOrPercentage::Percentage(per));
|
||||||
}
|
}
|
||||||
|
|
||||||
let num = try!(Number::parse_non_negative(input));
|
Number::parse_non_negative(input).map(NumberOrPercentage::Number)
|
||||||
Ok(NumberOrPercentage::Number(num))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue