From 50f1ba1ce8c61a1830d291cbffd0c5bc70cb79f6 Mon Sep 17 00:00:00 2001 From: Vincent Flyson Date: Sat, 24 Aug 2019 23:06:40 -0400 Subject: [PATCH] Treat network errors as empty results --- Cargo.toml | 2 +- src/html.rs | 200 +++++++++++++++++++++++++++------------------------- src/http.rs | 10 ++- 3 files changed, 108 insertions(+), 104 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 227295c..55f8b4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "monolith" -version = "2.0.12" +version = "2.0.13" authors = [ "Sunshine ", "Mahdi Robatipoor ", diff --git a/src/html.rs b/src/html.rs index d7925bc..e51d58a 100644 --- a/src/html.rs +++ b/src/html.rs @@ -9,19 +9,11 @@ use std::io; use utils::data_to_dataurl; lazy_static! { + static ref EMPTY_STRING: String = String::new(); static ref HAS_PROTOCOL: Regex = Regex::new(r"^[a-z0-9]+:").unwrap(); -} - -enum NodeMatch { - Icon, - Image, - Source, - StyleSheet, - Anchor, - Script, - Form, - IFrame, - Other, + static ref ICON_VALUES: Regex = Regex::new( + r"^icon|shortcut icon|mask-icon|apple-touch-icon$" + ).unwrap(); } const TRANSPARENT_PIXEL: &str = "data:image/png;base64,\ @@ -60,15 +52,11 @@ fn get_parent_node_name(node: &Handle) -> String { let parent_node = parent.and_then(|node| node.upgrade()).unwrap(); match &parent_node.data { - NodeData::Document => {"".to_string()} - NodeData::Doctype { .. } => {"".to_string()} - NodeData::Text { .. } => {"".to_string()} - NodeData::Comment { .. } => {"".to_string()} - NodeData::Element { - ref name, - attrs: _, - .. - } => { + NodeData::Document => { EMPTY_STRING.clone() } + NodeData::Doctype { .. } => { EMPTY_STRING.clone() } + NodeData::Text { .. } => { EMPTY_STRING.clone() } + NodeData::Comment { .. } => { EMPTY_STRING.clone() } + NodeData::Element { ref name, attrs: _, .. } => { name.local.as_ref().to_string() } NodeData::ProcessingInstruction { .. } => unreachable!() @@ -94,91 +82,117 @@ pub fn walk_and_embed_assets( ); } } - NodeData::Doctype { .. } => {} - NodeData::Text { .. } => {} - NodeData::Comment { .. } => { // Note: in case of opt_no_js being set to true, there's no need to worry about // getting rid of comments that may contain scripts, e.g.