mirror of
https://github.com/servo/servo.git
synced 2025-08-14 09:55:35 +01:00
Report an error for invalid CSS color values (bug 1381143).
This commit is contained in:
parent
cf5602e84f
commit
4b736354c4
6 changed files with 154 additions and 82 deletions
|
@ -38,7 +38,7 @@ use selectors::parser::SelectorParseError;
|
|||
#[cfg(feature = "servo")] use servo_config::prefs::PREFS;
|
||||
use shared_lock::StylesheetGuards;
|
||||
use style_traits::{PARSING_MODE_DEFAULT, HasViewportPercentage, ToCss, ParseError};
|
||||
use style_traits::{PropertyDeclarationParseError, StyleParseError};
|
||||
use style_traits::{PropertyDeclarationParseError, StyleParseError, ValueParseError};
|
||||
use stylesheets::{CssRuleType, MallocSizeOf, MallocSizeOfFn, Origin, UrlExtraData};
|
||||
#[cfg(feature = "servo")] use values::Either;
|
||||
use values::generics::text::LineHeight;
|
||||
|
@ -1489,7 +1489,8 @@ impl PropertyDeclaration {
|
|||
Ok(keyword) => DeclaredValueOwned::CSSWideKeyword(keyword),
|
||||
Err(_) => match ::custom_properties::SpecifiedValue::parse(context, input) {
|
||||
Ok(value) => DeclaredValueOwned::Value(value),
|
||||
Err(_) => return Err(PropertyDeclarationParseError::InvalidValue(name.to_string().into())),
|
||||
Err(e) => return Err(PropertyDeclarationParseError::InvalidValue(name.to_string().into(),
|
||||
ValueParseError::from_parse_error(e))),
|
||||
}
|
||||
};
|
||||
declarations.push(PropertyDeclaration::Custom(name, value));
|
||||
|
@ -1502,13 +1503,14 @@ impl PropertyDeclaration {
|
|||
input.look_for_var_functions();
|
||||
let start = input.position();
|
||||
input.parse_entirely(|input| id.parse_value(context, input))
|
||||
.or_else(|_| {
|
||||
.or_else(|err| {
|
||||
while let Ok(_) = input.next() {} // Look for var() after the error.
|
||||
if input.seen_var_functions() {
|
||||
input.reset(start);
|
||||
let (first_token_type, css) =
|
||||
::custom_properties::parse_non_custom_with_var(input).map_err(|_| {
|
||||
PropertyDeclarationParseError::InvalidValue(id.name().into())
|
||||
::custom_properties::parse_non_custom_with_var(input).map_err(|e| {
|
||||
PropertyDeclarationParseError::InvalidValue(id.name().into(),
|
||||
ValueParseError::from_parse_error(e))
|
||||
})?;
|
||||
Ok(PropertyDeclaration::WithVariables(id, Arc::new(UnparsedValue {
|
||||
css: css.into_owned(),
|
||||
|
@ -1517,7 +1519,8 @@ impl PropertyDeclaration {
|
|||
from_shorthand: None,
|
||||
})))
|
||||
} else {
|
||||
Err(PropertyDeclarationParseError::InvalidValue(id.name().into()))
|
||||
Err(PropertyDeclarationParseError::InvalidValue(id.name().into(),
|
||||
ValueParseError::from_parse_error(err)))
|
||||
}
|
||||
})
|
||||
}).map(|declaration| {
|
||||
|
@ -1539,13 +1542,14 @@ impl PropertyDeclaration {
|
|||
let start = input.position();
|
||||
// Not using parse_entirely here: each ${shorthand.ident}::parse_into function
|
||||
// needs to do so *before* pushing to `declarations`.
|
||||
id.parse_into(declarations, context, input).or_else(|_| {
|
||||
id.parse_into(declarations, context, input).or_else(|err| {
|
||||
while let Ok(_) = input.next() {} // Look for var() after the error.
|
||||
if input.seen_var_functions() {
|
||||
input.reset(start);
|
||||
let (first_token_type, css) =
|
||||
::custom_properties::parse_non_custom_with_var(input).map_err(|_| {
|
||||
PropertyDeclarationParseError::InvalidValue(id.name().into())
|
||||
::custom_properties::parse_non_custom_with_var(input).map_err(|e| {
|
||||
PropertyDeclarationParseError::InvalidValue(id.name().into(),
|
||||
ValueParseError::from_parse_error(e))
|
||||
})?;
|
||||
let unparsed = Arc::new(UnparsedValue {
|
||||
css: css.into_owned(),
|
||||
|
@ -1564,7 +1568,8 @@ impl PropertyDeclaration {
|
|||
}
|
||||
Ok(())
|
||||
} else {
|
||||
Err(PropertyDeclarationParseError::InvalidValue(id.name().into()))
|
||||
Err(PropertyDeclarationParseError::InvalidValue(id.name().into(),
|
||||
ValueParseError::from_parse_error(err)))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue