aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-05-29 07:46:41 -0700
committerFuwn <[email protected]>2024-05-29 07:46:41 -0700
commit5e89f7165a916c0566cc0d162b7dba16d71cceaf (patch)
treed3c01cf965b11ac23d58aec326e6a1af93b5d9af
parentfeat(web): image parsing (diff)
downloadlocus-5e89f7165a916c0566cc0d162b7dba16d71cceaf.tar.xz
locus-5e89f7165a916c0566cc0d162b7dba16d71cceaf.zip
fix(web): simple proxy escape
-rw-r--r--src/modules/web.rs53
1 files changed, 18 insertions, 35 deletions
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, <https://fuwn.me/web>, 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("<img") {
return;
}
@@ -104,7 +103,7 @@ To visit the web version of this exact page, <https://fuwn.me/web>, 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, <https://fuwn.me/web>, 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, <https://fuwn.me/web>, 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("<summary>")
{
- 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("")