From 5c97b40ea61252ee096bc904e76c4a6ac4b4dea3 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 4 Jul 2024 04:42:20 +0200 Subject: [PATCH] fix(web): dont recreate regex every time --- web/src/components/user.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/src/components/user.rs b/web/src/components/user.rs index d99bee7..40121ea 100644 --- a/web/src/components/user.rs +++ b/web/src/components/user.rs @@ -3,6 +3,10 @@ use crate::{prelude::*, DEFAULT_AVATAR_URL}; use apb::{field::OptionalString, Activity, ActivityMut, Actor, Base, Object, ObjectMut}; +lazy_static::lazy_static! { + static ref REGEX: regex::Regex = regex::Regex::new(r":\w+:").expect("failed compiling custom emoji regex"); +} + #[component] pub fn ActorStrip(object: crate::Object) -> impl IntoView { let actor_id = object.id().unwrap_or_default().to_string(); @@ -51,8 +55,7 @@ pub fn ActorBanner(object: crate::Object) -> impl IntoView { #[component] fn DisplayName(mut name: String) -> impl IntoView { - let custom_emoji_regex = regex::Regex::new(r":\w+:").expect("failed compiling regex pattern"); - for m in custom_emoji_regex.find_iter(&name.clone()) { + for m in REGEX.find_iter(&name.clone()) { // TODO this is a clear unmitigated unsanitized html injection ahahahahaha but accounts // with many custom emojis in their names mess with my frontend and i dont want to // deal with it rn