Merge pull request #191 from snshn/trim-style

Trim CSS if it contains nothing but whitespaces
This commit is contained in:
Sunshine 2020-06-26 23:41:41 -04:00 committed by GitHub
commit fb835fae28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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)
}

View file

@ -143,7 +143,7 @@ mod passing {
std::str::from_utf8(&out.stdout).unwrap(),
"<html><head>\
<meta http-equiv=\"Content-Security-Policy\" content=\"font-src 'none';\"></meta>\
<style> </style>\
<style></style>\
</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]
fn style_exclude_unquoted_images() {
let cache = &mut HashMap::new();