trim CSS if it contains nothing but whitespaces

pull/191/head
Sunshine 4 years ago
parent d67483cf8e
commit 29bf042da0
No known key found for this signature in database
GPG Key ID: B80CA68703CD8AB1

@ -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)
} }

@ -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"
); );

@ -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();

Loading…
Cancel
Save