From 14519508e9e02760ddd1a7b2c91ad79968329198 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 30 Aug 2024 05:55:13 +0300 Subject: Fix URL regex --- src/main/java/com/juick/util/MessageUtils.java | 2 +- src/test/java/com/juick/MessageTest.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/java/com/juick/util/MessageUtils.java b/src/main/java/com/juick/util/MessageUtils.java index 42c97d84..316adb90 100644 --- a/src/main/java/com/juick/util/MessageUtils.java +++ b/src/main/java/com/juick/util/MessageUtils.java @@ -57,7 +57,7 @@ public class MessageUtils { private final static String urlWhiteSpacePrefix = "((?<=\\s)|(?<=\\A))"; - private final static String urlRegex = "((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\n\\\"]+)/?[^\\]\\s\\n\\\"\\>]*)"; + private final static String urlRegex = "((?:(?:ht|f)tps?://(?:www\\.)?([^\\s()<>/?#]+)([^\\s()<>]*)?))"; private final static String urlWithWhitespacesRegex = urlWhiteSpacePrefix + urlRegex; diff --git a/src/test/java/com/juick/MessageTest.java b/src/test/java/com/juick/MessageTest.java index 14d6175a..6ce01f4a 100644 --- a/src/test/java/com/juick/MessageTest.java +++ b/src/test/java/com/juick/MessageTest.java @@ -213,8 +213,8 @@ public class MessageTest { assertThat(MessageUtils.formatMessage(msg), is("
quote
message")); String brokenComment = "