From 74c96ae46f17b651a5b8787f6569b22d1de5db54 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 29 Nov 2023 18:00:37 -0800 Subject: [PATCH] Hide /content/ HTML inscriptions --- src/inscription.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/inscription.rs b/src/inscription.rs index 89f503130e..b2e415204f 100644 --- a/src/inscription.rs +++ b/src/inscription.rs @@ -308,6 +308,10 @@ impl Inscription { } pub(crate) fn hidden(&self) -> bool { + lazy_static! { + static ref CONTENT: Regex = Regex::new(r"^\s*/content/[[:xdigit:]]{64}i\d+\s*$").unwrap(); + } + let Some(content_type) = self.content_type() else { return true; }; @@ -320,6 +324,16 @@ impl Inscription { return true; } + if content_type.starts_with("text/html") + && self + .body() + .and_then(|body| str::from_utf8(body).ok()) + .map(|body| CONTENT.is_match(body)) + .unwrap_or_default() + { + return true; + } + false } } @@ -796,6 +810,26 @@ mod tests { case(Some("text/plain;charset=utf-8"), Some("foo"), true); case(Some("text/plain;charset=cn-big5"), Some("foo"), true); case(Some("application/json"), Some("foo"), true); + case( + Some("text/markdown"), + Some("/content/09a8d837ec0bcaec668ecf405e696a16bee5990863659c224ff888fb6f8f45e7i0"), + false, + ); + case( + Some("text/html"), + Some("/content/09a8d837ec0bcaec668ecf405e696a16bee5990863659c224ff888fb6f8f45e7i0"), + true, + ); + case( + Some("text/html;charset=utf-8"), + Some("/content/09a8d837ec0bcaec668ecf405e696a16bee5990863659c224ff888fb6f8f45e7i0"), + true, + ); + case( + Some("text/html"), + Some(" /content/09a8d837ec0bcaec668ecf405e696a16bee5990863659c224ff888fb6f8f45e7i0 \n"), + true, + ); assert!(Inscription { content_type: Some("text/plain".as_bytes().into()),