Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of "center left" in parse_origin (fixes #15750) #16435

Merged
merged 1 commit into from Apr 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion components/style/properties/longhand/effects.mako.rs
Expand Up @@ -439,7 +439,7 @@ pub struct OriginParseResult {

pub fn parse_origin(context: &ParserContext, input: &mut Parser) -> Result<OriginParseResult,()> {
use values::specified::{LengthOrPercentage, Percentage};
let (mut horizontal, mut vertical, mut depth) = (None, None, None);
let (mut horizontal, mut vertical, mut depth, mut horizontal_is_center) = (None, None, None, false);
loop {
if let Err(_) = input.try(|input| {
let token = try!(input.expect_ident());
Expand All @@ -448,12 +448,16 @@ pub fn parse_origin(context: &ParserContext, input: &mut Parser) -> Result<Origi
"left" => {
if horizontal.is_none() {
horizontal = Some(LengthOrPercentage::Percentage(Percentage(0.0)))
} else if horizontal_is_center && vertical.is_none() {
vertical = Some(LengthOrPercentage::Percentage(Percentage(0.5)));
horizontal = Some(LengthOrPercentage::Percentage(Percentage(0.0)));
} else {
return Err(())
}
},
"center" => {
if horizontal.is_none() {
horizontal_is_center = true;
horizontal = Some(LengthOrPercentage::Percentage(Percentage(0.5)))
} else if vertical.is_none() {
vertical = Some(LengthOrPercentage::Percentage(Percentage(0.5)))
Expand All @@ -464,6 +468,9 @@ pub fn parse_origin(context: &ParserContext, input: &mut Parser) -> Result<Origi
"right" => {
if horizontal.is_none() {
horizontal = Some(LengthOrPercentage::Percentage(Percentage(1.0)))
} else if horizontal_is_center && vertical.is_none() {
vertical = Some(LengthOrPercentage::Percentage(Percentage(0.5)));
horizontal = Some(LengthOrPercentage::Percentage(Percentage(1.0)));
} else {
return Err(())
}
Expand Down
17 changes: 16 additions & 1 deletion tests/unit/style/parsing/effects.rs
Expand Up @@ -51,10 +51,25 @@ fn test_longhands_parse_origin() {
assert!(parsed.is_ok());
assert_eq!(parser.is_exhausted(), true);

let mut parser = Parser::new("1px");
let mut parser = Parser::new("center left");
let parsed = longhands::parse_origin(&context, &mut parser);
assert!(parsed.is_ok());
assert_eq!(parser.is_exhausted(), true);

let mut parser = Parser::new("center right");
let parsed = longhands::parse_origin(&context, &mut parser);
assert!(parsed.is_ok());
assert_eq!(parser.is_exhausted(), true);

let mut parser = Parser::new("center right 1px");
let parsed = longhands::parse_origin(&context, &mut parser);
assert!(parsed.is_ok());
assert_eq!(parser.is_exhausted(), true);

let mut parser = Parser::new("1% right");
let parsed = longhands::parse_origin(&context, &mut parser);
assert!(parsed.is_ok());
assert_eq!(parser.is_exhausted(), false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just assert!(!parser.is_exhausted()) (same for the others)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(though I guess it's pre-existing, hmm..)

}

#[test]
Expand Down