Ignore empty src in images, accept fluid icons

pull/57/head
Vincent Flyson 5 years ago
parent facc992881
commit 04cbbefafa

@ -1,6 +1,6 @@
[package]
name = "monolith"
version = "2.0.16"
version = "2.0.17"
authors = [
"Sunshine <sunshine@uberspace.net>",
"Mahdi Robatipoor <mahdi.robatipoor@gmail.com>",

@ -12,7 +12,7 @@ lazy_static! {
static ref EMPTY_STRING: String = String::new();
static ref HAS_PROTOCOL: Regex = Regex::new(r"^[a-z0-9]+:").unwrap();
static ref ICON_VALUES: Regex = Regex::new(
r"^icon|shortcut icon|mask-icon|apple-touch-icon$"
r"^icon|shortcut icon|mask-icon|apple-touch-icon|fluid-icon$"
).unwrap();
}
@ -181,13 +181,20 @@ pub fn walk_and_embed_assets(
"img" => {
for attr in attrs_mut.iter_mut() {
if &attr.name.local == "src" {
let value = attr.value.to_string();
// Ignore images with empty source (they're hopelessly broken)
if value == EMPTY_STRING.clone() {
continue;
}
if opt_no_images {
attr.value.clear();
attr.value.push_slice(TRANSPARENT_PIXEL);
} else {
let src_full_url: String = resolve_url(
&url,
&attr.value.to_string(),
&value,
)
.unwrap_or(EMPTY_STRING.clone());
let img_datauri = retrieve_asset(
@ -284,7 +291,7 @@ pub fn walk_and_embed_assets(
"form" => {
for attr in attrs_mut.iter_mut() {
if &attr.name.local == "action" {
// Do not touch action props which are set to a URL
// Don't modify action that's already a full URL
if is_valid_url(&attr.value) {
continue;
}
@ -300,12 +307,12 @@ pub fn walk_and_embed_assets(
for attr in attrs_mut.iter_mut() {
if &attr.name.local == "src" {
let value = attr.value.to_string();
// Ignore iframes with empty source (they cause infinite loops)
if value == EMPTY_STRING.clone() {
continue;
}
let src_full_url: String = resolve_url(&url, &value)
.unwrap_or(EMPTY_STRING.clone());
let iframe_data = retrieve_asset(
@ -392,6 +399,8 @@ mod tests {
assert_eq!(is_icon("icon"), true);
assert_eq!(is_icon("Shortcut Icon"), true);
assert_eq!(is_icon("ICON"), true);
assert_eq!(is_icon("mask-icon"), true);
assert_eq!(is_icon("fluid-icon"), true);
assert_eq!(is_icon("stylesheet"), false);
assert_eq!(is_icon(""), false);
}

@ -91,6 +91,7 @@ mod tests {
fn test_is_valid_url() {
assert!(is_valid_url("https://www.rust-lang.org/"));
assert!(is_valid_url("http://kernel.org"));
assert!(!is_valid_url("//kernel.org"));
assert!(!is_valid_url("./index.html"));
assert!(!is_valid_url("some-local-page.htm"));
assert!(!is_valid_url("ftp://1.2.3.4/www/index.html"));

Loading…
Cancel
Save