properly parse negative units in CSS

pull/155/head
Sunshine 4 years ago
parent 5a30c6b44b
commit 349c7bb3ea
No known key found for this signature in database
GPG Key ID: B80CA68703CD8AB1

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

@ -197,3 +197,30 @@ body {\n \
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
);
}

Loading…
Cancel
Save