From 598f6374b3eb7696b72966bb9ecf7ed0cdf6522c Mon Sep 17 00:00:00 2001
From: Paul <paulmakles@gmail.com>
Date: Wed, 16 Jun 2021 16:43:17 +0100
Subject: [PATCH] Messaging: Don't embed URLs in code.

---
 src/database/entities/microservice/january.rs | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/database/entities/microservice/january.rs b/src/database/entities/microservice/january.rs
index c52d36f..5eee2b5 100644
--- a/src/database/entities/microservice/january.rs
+++ b/src/database/entities/microservice/january.rs
@@ -4,6 +4,7 @@ use crate::util::{
 };
 use linkify::{LinkFinder, LinkKind};
 use serde::{Deserialize, Serialize};
+use regex::Regex;
 
 #[derive(Serialize, Deserialize, Debug, Clone)]
 pub enum ImageSize {
@@ -97,10 +98,17 @@ pub enum Embed {
 
 impl Embed {
     pub async fn generate(content: String) -> Result<Vec<Embed>> {
+        lazy_static! {
+            static ref RE_CODE: Regex = Regex::new("```(?:.|\n)+?```|`(?:.|\n)+?`").unwrap();
+        }
+
+        // Ignore code blocks.
+        let content = RE_CODE.replace_all(&content, "");
+
         let content = content
+            // Ignore quoted lines.
             .split("\n")
             .map(|v| {
-                // Ignore quoted lines.
                 if let Some(c) = v.chars().next() {
                     if c == '>' {
                         return "";
-- 
GitLab