From 8d45cc5827f9fb3f6535749cc7d5c624fc08f5b5 Mon Sep 17 00:00:00 2001 From: Millesimus Date: Sat, 4 Sep 2021 15:56:37 +0200 Subject: [PATCH] Fixing trailing characters treated as part of URI error (#3938). --- .../java/eu/siacs/conversations/utils/Patterns.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/utils/Patterns.java b/src/main/java/eu/siacs/conversations/utils/Patterns.java index fae13aaea..d220b3326 100644 --- a/src/main/java/eu/siacs/conversations/utils/Patterns.java +++ b/src/main/java/eu/siacs/conversations/utils/Patterns.java @@ -304,9 +304,15 @@ public class Patterns { + "\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_" + "\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@"; private static final String PORT_NUMBER = "\\:\\d{1,5}"; + private static final String PATH_AND_QUERY_CHARS_WITHOUT_SLASH = + "\\;\\?\\:\\@\\&\\=\\#\\~" // plus optional query params + + "\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_"; private static final String PATH_AND_QUERY = "\\/(?:(?:[" + LABEL_CHAR - + "\\;\\/\\?\\:\\@\\&\\=\\#\\~" // plus optional query params - + "\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*"; + + PATH_AND_QUERY_CHARS_WITHOUT_SLASH + + "]+[^" + PATH_AND_QUERY_CHARS_WITHOUT_SLASH + "\\s]" // path and query chars must not be trailing + + "|\\/" // trailing slashes are fine + + ")|(?:\\%[a-fA-F0-9]{2}))*"; + /** * Regular expression pattern to match most part of RFC 3987 * Internationalized URLs, aka IRIs.