From 07ed1b82571a4956f5aa6bc3c40e0a6d88793a42 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 16 Feb 2018 12:18:38 +0100 Subject: [PATCH] Guard RedisURI creation against URI without scheme #694 --- src/main/java/com/lambdaworks/redis/RedisURI.java | 4 ++++ src/test/java/com/lambdaworks/redis/RedisURITest.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/main/java/com/lambdaworks/redis/RedisURI.java b/src/main/java/com/lambdaworks/redis/RedisURI.java index aed60afd11..5d2212101e 100644 --- a/src/main/java/com/lambdaworks/redis/RedisURI.java +++ b/src/main/java/com/lambdaworks/redis/RedisURI.java @@ -504,6 +504,10 @@ public URI toURI() { } private static RedisURI buildRedisUriFromUri(URI uri) { + + LettuceAssert.notNull(uri, "URI must not be null"); + LettuceAssert.notNull(uri.getScheme(), "URI scheme must not be null"); + Builder builder; if (uri.getScheme().equals(URI_SCHEME_REDIS_SENTINEL)) { builder = configureSentinel(uri); diff --git a/src/test/java/com/lambdaworks/redis/RedisURITest.java b/src/test/java/com/lambdaworks/redis/RedisURITest.java index 6275405a37..d2708e4a7c 100644 --- a/src/test/java/com/lambdaworks/redis/RedisURITest.java +++ b/src/test/java/com/lambdaworks/redis/RedisURITest.java @@ -76,6 +76,11 @@ public void simpleUriTest() { assertThat(redisURI.toURI().toString()).isEqualTo("redis://localhost"); } + @Test(expected = IllegalArgumentException.class) + public void shouldThrowIllegalArgumentExceptionOnMalformedUri() { + RedisURI.create("localhost"); + } + @Test public void sslUriTest() { RedisURI redisURI = RedisURI.create("redis+ssl://localhost:6379");