properly parse negative units in CSS

This commit is contained in:
Sunshine 2020-04-08 18:07:39 -04:00
parent 5a30c6b44b
commit 349c7bb3ea
No known key found for this signature in database
GPG key ID: B80CA68703CD8AB1
2 changed files with 33 additions and 2 deletions

View file

@ -217,17 +217,21 @@ pub fn process_css<'a>(
ref unit_value, ref unit_value,
.. ..
} => { } => {
if *has_sign { if *has_sign && *unit_value >= 0. {
result.push_str("-"); result.push_str("+");
} }
result.push_str(str!(unit_value * 100.).as_str()); result.push_str(str!(unit_value * 100.).as_str());
result.push_str("%"); result.push_str("%");
} }
Token::Dimension { Token::Dimension {
ref has_sign,
ref value, ref value,
ref unit, ref unit,
.. ..
} => { } => {
if *has_sign && *value >= 0. {
result.push_str("+");
}
result.push_str(str!(value).as_str()); result.push_str(str!(value).as_str());
result.push_str(str!(unit).as_str()); result.push_str(str!(unit).as_str());
} }

View file

@ -197,3 +197,30 @@ body {\n \
CSS CSS
); );
} }
#[test]
fn passing_transform_percentages_and_degrees() {
let cache = &mut HashMap::new();
let client = Client::new();
const CSS: &str = "\
div {\n \
transform: translate(-50%, -50%) rotate(-45deg);\n\
transform: translate(50%, 50%) rotate(45deg);\n\
transform: translate(+50%, +50%) rotate(+45deg);\n\
}\n\
\n\
";
assert_eq!(
css::embed_css(
cache,
&client,
"https://doesntmatter.local/",
&CSS,
false,
true,
),
CSS
);
}