From 349c7bb3ea809b1ac23fad459324e843a06cc110 Mon Sep 17 00:00:00 2001 From: Sunshine Date: Wed, 8 Apr 2020 18:07:39 -0400 Subject: [PATCH] properly parse negative units in CSS --- src/css.rs | 8 ++++++-- src/tests/css/embed_css.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/css.rs b/src/css.rs index 83938bc..67317ab 100644 --- a/src/css.rs +++ b/src/css.rs @@ -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()); } diff --git a/src/tests/css/embed_css.rs b/src/tests/css/embed_css.rs index e4e2b58..28261c0 100644 --- a/src/tests/css/embed_css.rs +++ b/src/tests/css/embed_css.rs @@ -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 + ); +}