From 5619a9173f8f6eb364568df8c711d18f71afef66 Mon Sep 17 00:00:00 2001 From: Matheus Cruz Date: Sat, 28 Sep 2024 00:26:07 -0300 Subject: [PATCH] Remove throws exception when is reserved --- .../client/VertxRedisClientFactory.java | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/VertxRedisClientFactory.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/VertxRedisClientFactory.java index fecdbbe8963da6..29b03838614645 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/VertxRedisClientFactory.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/VertxRedisClientFactory.java @@ -45,6 +45,7 @@ public class VertxRedisClientFactory { public static final String DEFAULT_CLIENT = ""; + public static String NON_RESERVED_URI_PATTERN = "[^a-zA-Z0-9\\-_.~]"; private static final Logger LOGGER = Logger.getLogger(VertxRedisClientFactory.class); @@ -56,8 +57,6 @@ public static Redis create(String name, Vertx vertx, RedisClientConfig config, T RedisOptions options = new RedisOptions(); Consumer> configureOptions = new Consumer>() { - static String NON_RESERVED_PATTERN = "[^a-zA-Z0-9\\-_.~]"; - @Override public void accept(Set uris) { for (URI uri : uris) { @@ -70,32 +69,6 @@ public void accept(Set uris) { } } } - - public String validate(String input) { - if (input.matches(".*" + NON_RESERVED_PATTERN + ".*")) { - throw new IllegalArgumentException( - "Was not possible to configure the Redis connection string with the client " + - "query parameter: Only " + NON_RESERVED_PATTERN - + " characters are supported, please provide a client " + - "name with a right pattern."); - } - return input; - } - - private String applyClientQueryParam(String client, URI uri) { - validate(client); - String encodedClient = URLEncoder.encode(client, StandardCharsets.UTF_8); - String query = uri.getQuery() == null ? "client=" + encodedClient - : uri.getQuery() + "&client=" + encodedClient; - try { - return new URI( - uri.getScheme(), uri.getAuthority(), uri.getPath(), query, uri.getFragment()).toString().trim(); - } catch (URISyntaxException e) { - LOGGER.warnf("Was not possible to generate a new Redis URL with client query parameter," + - "the value is: %s", client); - return uri.toString().trim(); - } - } }; List hosts = new ArrayList<>(); @@ -150,6 +123,31 @@ private String applyClientQueryParam(String client, URI uri) { return Redis.createClient(vertx, options); } + private static String applyClientQueryParam(String client, URI uri) { + + if (client.matches(".*" + NON_RESERVED_URI_PATTERN + ".*")) { + LOGGER.warnf("The client query parameter contains reserved URI characters. " + + "This may result in an incorrect client name after URI encoding."); + } + + String encodedClient = URLEncoder.encode(client, StandardCharsets.UTF_8); + String query = uri.getQuery() == null ? "client=" + encodedClient + : uri.getQuery() + "&client=" + encodedClient; + try { + return new URI( + uri.getScheme(), uri.getAuthority(), uri.getPath(), query, uri.getFragment()).toString().trim(); + } catch (URISyntaxException e) { + LOGGER.warnf("Was not possible to generate a new Redis URL with client query parameter," + + "the value is: %s", client); + return uri.toString().trim(); + } + } + + public static String checkClient(String input) { + + return input; + } + private static void customize(String name, RedisOptions options) { if (Arc.container() != null) { List> customizers = Arc.container().listAll(RedisOptionsCustomizer.class);