From 04cbbefafa239ccb83a5bc3c2995f42d3ffe35c1 Mon Sep 17 00:00:00 2001 From: Vincent Flyson Date: Sun, 8 Sep 2019 02:48:07 -0400 Subject: [PATCH] Ignore empty src in images, accept fluid icons --- Cargo.toml | 2 +- src/html.rs | 17 +++++++++++++---- src/http.rs | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e15cd6d..f30d76c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "monolith" -version = "2.0.16" +version = "2.0.17" authors = [ "Sunshine ", "Mahdi Robatipoor ", diff --git a/src/html.rs b/src/html.rs index 76730ab..b3be66d 100644 --- a/src/html.rs +++ b/src/html.rs @@ -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); } diff --git a/src/http.rs b/src/http.rs index d48ab42..54034b3 100644 --- a/src/http.rs +++ b/src/http.rs @@ -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"));