Skip to content

Commit

Permalink
Fixed - Redis or Valkey hostname parsing. #3807
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Koksharov committed Dec 5, 2024
1 parent a0d9331 commit 621ec94
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions redisson/src/main/java/org/redisson/misc/RedisURI.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public RedisURI(String uri) {
password = URLDecoder.decode(details[1], StandardCharsets.UTF_8.toString());
}
}
if (url.getHost().isEmpty()) {
throw new IllegalArgumentException("Redis host can't be parsed");
}

host = url.getHost();
port = url.getPort();
ssl = uri.startsWith("rediss://");
Expand Down
8 changes: 8 additions & 0 deletions redisson/src/test/java/org/redisson/misc/RedisURITest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.redisson.misc;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -28,6 +29,13 @@ public void testIPv6Braces() {
assertThat(uri2.getPort()).isEqualTo(6379);
}

@Test
public void testHostname() {
Assertions.assertThrowsExactly(IllegalArgumentException.class, () -> {
new RedisURI("redis:///localhost:15319");
}, "Redis host can't be parsed");
}

@Test
public void testUsernamePassword() {
RedisURI uri1 = new RedisURI("redis://user:[email protected]:15319");
Expand Down

0 comments on commit 621ec94

Please sign in to comment.