From 88ffde0c3bcc6302d14fb7edb284c4621874d59b Mon Sep 17 00:00:00 2001 From: Sunshine Date: Thu, 26 Dec 2019 09:44:01 -0500 Subject: [PATCH] wipe integrity attributes --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/html.rs | 22 ++++++++++++++++++++++ src/tests/html.rs | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ef3522..aaba5cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -625,7 +625,7 @@ dependencies = [ [[package]] name = "monolith" -version = "2.1.0" +version = "2.1.1" dependencies = [ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 901fe35..f1407df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "monolith" -version = "2.1.0" +version = "2.1.1" authors = [ "Sunshine ", "Mahdi Robatipoor ", diff --git a/src/html.rs b/src/html.rs index 869c220..c494cf9 100644 --- a/src/html.rs +++ b/src/html.rs @@ -79,6 +79,17 @@ pub fn walk_and_embed_assets( "link" => { let mut link_type: &str = ""; + // Remove integrity attributes + let mut i = 0; + while i < attrs_mut.len() { + let attr_name = attrs_mut[i].name.local.as_ref(); + if attr_name.eq_ignore_ascii_case("integrity") { + attrs_mut.remove(i); + } else { + i += 1; + } + } + for attr in attrs_mut.iter_mut() { if &attr.name.local == "rel" { if is_icon(&attr.value.to_string()) { @@ -263,6 +274,17 @@ pub fn walk_and_embed_assets( } } "script" => { + // Remove integrity attributes + let mut i = 0; + while i < attrs_mut.len() { + let attr_name = attrs_mut[i].name.local.as_ref(); + if attr_name.eq_ignore_ascii_case("integrity") { + attrs_mut.remove(i); + } else { + i += 1; + } + } + if opt_no_js { // Empty src and inner content of SCRIPT tags for attr in attrs_mut.iter_mut() { diff --git a/src/tests/html.rs b/src/tests/html.rs index a91e34e..70d4e2c 100644 --- a/src/tests/html.rs +++ b/src/tests/html.rs @@ -298,6 +298,45 @@ fn test_walk_and_embed_assets_no_js() { ); } +#[test] +fn test_walk_and_embed_with_no_integrity() { + let html = "No integrity\ + \ + "; + let dom = html_to_dom(&html); + let url = "http://localhost"; + let cache = &mut HashMap::new(); + let client = reqwest::Client::new(); + let opt_no_css: bool = true; + let opt_no_frames: bool = true; + let opt_no_js: bool = true; + let opt_no_images: bool = true; + let opt_silent = true; + + walk_and_embed_assets( + cache, + &client, + &url, + &dom.document, + opt_no_css, + opt_no_js, + opt_no_images, + opt_silent, + opt_no_frames, + ); + + let mut buf: Vec = Vec::new(); + serialize(&mut buf, &dom.document, SerializeOpts::default()).unwrap(); + + assert_eq!( + buf.iter().map(|&c| c as char).collect::(), + "\ + No integrity\ + \ + " + ); +} + #[test] fn test_stringify_document() { let html = "
";