trim CSS if it contains nothing but whitespaces

This commit is contained in:
Sunshine 2020-06-26 23:22:35 -04:00
parent d67483cf8e
commit 29bf042da0
No known key found for this signature in database
GPG key ID: B80CA68703CD8AB1
3 changed files with 25 additions and 1 deletions

View file

@ -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) Ok(result)
} }

View file

@ -143,7 +143,7 @@ mod passing {
std::str::from_utf8(&out.stdout).unwrap(), std::str::from_utf8(&out.stdout).unwrap(),
"<html><head>\ "<html><head>\
<meta http-equiv=\"Content-Security-Policy\" content=\"font-src 'none';\"></meta>\ <meta http-equiv=\"Content-Security-Policy\" content=\"font-src 'none';\"></meta>\
<style> </style>\ <style></style>\
</head><body>Hi</body></html>\n" </head><body>Hi</body></html>\n"
); );

View file

@ -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] #[test]
fn style_exclude_unquoted_images() { fn style_exclude_unquoted_images() {
let cache = &mut HashMap::new(); let cache = &mut HashMap::new();