diff --git a/src/css.rs b/src/css.rs index 1abe8cd..6be5de6 100644 --- a/src/css.rs +++ b/src/css.rs @@ -394,6 +394,11 @@ pub fn process_css<'a>( } } + // Ensure empty CSS is really empty + if result.len() > 0 && result.trim().len() == 0 { + result = result.trim().to_string() + } + Ok(result) } diff --git a/src/tests/cli.rs b/src/tests/cli.rs index b685cbb..98e7ff4 100644 --- a/src/tests/cli.rs +++ b/src/tests/cli.rs @@ -143,7 +143,7 @@ mod passing { std::str::from_utf8(&out.stdout).unwrap(), "
\ \ - \ + \ Hi\n" ); diff --git a/src/tests/css/embed_css.rs b/src/tests/css/embed_css.rs index b34aea6..f862c92 100644 --- a/src/tests/css/embed_css.rs +++ b/src/tests/css/embed_css.rs @@ -22,6 +22,25 @@ mod passing { ); } + #[test] + fn trim_if_empty() { + let cache = &mut HashMap::new(); + let client = Client::new(); + + assert_eq!( + css::embed_css( + cache, + &client, + "https://doesntmatter.local/", + "\t \t ", + false, + false, + false, + ), + "" + ); + } + #[test] fn style_exclude_unquoted_images() { let cache = &mut HashMap::new();