From 5e89f7165a916c0566cc0d162b7dba16d71cceaf Mon Sep 17 00:00:00 2001 From: Fuwn Date: Wed, 29 May 2024 07:46:41 -0700 Subject: fix(web): simple proxy escape --- src/modules/web.rs | 53 ++++++++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/modules/web.rs b/src/modules/web.rs index d730370..ccbf4fd 100644 --- a/src/modules/web.rs +++ b/src/modules/web.rs @@ -82,14 +82,13 @@ To visit the web version of this exact page, , you would vi }; let parser = dom.parser(); let mut nodes = dom.nodes().iter().peekable(); - let mut in_proxy_information = false; while let Some(element) = nodes.next() { let mut text = String::new(); let () = element.as_tag().map_or((), |tag| { match tag.name().as_utf8_str().to_string().as_str() { - "p" if !in_proxy_information => { + "p" => { if tag.inner_html(parser).contains(", you would vi .unwrap_or(&"A parse error occurred in this location.") )); } - "a" if !in_proxy_information => { + "a" => { contents.pop(); contents.push(format!( "=> {} {}\n{}", @@ -126,29 +125,29 @@ To visit the web version of this exact page, , you would vi }) )); } - "h1" if !in_proxy_information => { + "h1" => { contents.push(format!( "{}# {}\n\n", if contents.is_empty() { "\n" } else { "" }, tag.inner_text(parser) )); } - "h2" if !in_proxy_information => { + "h2" => { contents.push(format!("\n## {}\n\n", tag.inner_text(parser))); } - "h3" if !in_proxy_information => { + "h3" => { contents.push(format!("\n### {}\n\n", tag.inner_text(parser))); } - "pre" if !in_proxy_information => { + "pre" => { contents.push(format!("```\n{}```\n", tag.inner_text(parser))); } - "blockquote" if !in_proxy_information => { + "blockquote" => { contents.push(format!("> {}\n\n", tag.inner_text(parser))); } - "li" if !in_proxy_information => { + "li" => { contents.push(format!("* {}\n", tag.inner_text(parser))); } - "img" if !in_proxy_information => { + "img" => { contents.push(format!( "=> {} {}\n\n", tag.attributes().get("src").flatten().map_or( @@ -162,40 +161,24 @@ To visit the web version of this exact page, , you would vi )); } "html" | "head" | "script" | "link" | "title" | "body" | "ul" - | "style" - if !in_proxy_information => {} + | "style" => {} _ => { text = tag.inner_text(parser).to_string(); - if (text.contains("Proxy Information") + if !(text.contains("Proxy Information") || text.contains("Proxied content from")) - && tag.inner_html(parser).contains("") { - in_proxy_information = true; - - return; - } - - if (text.contains("This content has been proxied by September") - || text.contains( - "Be advised that no attempt was made to verify the remote \ - SSL certificate.", - )) - && in_proxy_information - { - in_proxy_information = false; - - return; + contents.push(format!("{text}\n\n")); } - - if in_proxy_information { - return; - } - - contents.push(format!("{}\n\n", tag.inner_text(parser))); } } }); + + if text.contains("Proxy Information") + || text.contains("Proxied content from") + { + break; + } } contents.join("") -- cgit v1.2.3