From 7678286fb3efa7bd7719ffe3055da9ed01e9f2f9 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 11 Apr 2024 08:49:11 +0200 Subject: [PATCH] Refine UriComponentsBuilder parsing This commit refines the expressions for the scheme, user info, host and port parts of the URL in UriComponentsBuilder to better conform to RFC 3986. Fixes gh-32618 --- .../springframework/web/util/UriComponentsBuilder.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java index 99a134e9bfbc..4d1d07c808ad 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java @@ -73,19 +73,19 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { private static final Pattern QUERY_PARAM_PATTERN = Pattern.compile("([^&=]+)(=?)([^&]+)?"); - private static final String SCHEME_PATTERN = "([^:/?#]+):"; + private static final String SCHEME_PATTERN = "([^:/?#\\\\]+):"; private static final String HTTP_PATTERN = "(?i)(http|https):"; - private static final String USERINFO_PATTERN = "([^/?#]*)"; + private static final String USERINFO_PATTERN = "([^/?#\\\\]*)"; - private static final String HOST_IPV4_PATTERN = "[^/?#:]*"; + private static final String HOST_IPV4_PATTERN = "[^/?#:\\\\]*"; private static final String HOST_IPV6_PATTERN = "\\[[\\p{XDigit}:.]*[%\\p{Alnum}]*]"; private static final String HOST_PATTERN = "(" + HOST_IPV6_PATTERN + "|" + HOST_IPV4_PATTERN + ")"; - private static final String PORT_PATTERN = "(\\{[^}]+\\}?|[^/?#]*)"; + private static final String PORT_PATTERN = "(\\{[^}]+\\}?|[^/?#\\\\]*)"; private static final String PATH_PATTERN = "([^?#]*)";