Skip to content

Commit 11f700a

Browse files
committed
Fix handling of redis password containing a colon
Closes gh-11371
1 parent 4ecc7b9 commit 11f700a

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -129,7 +129,7 @@ private void configureConnectionFromUrl(JedisConnectionFactory factory) {
129129
factory.setPort(uri.getPort());
130130
if (uri.getUserInfo() != null) {
131131
String password = uri.getUserInfo();
132-
int index = password.lastIndexOf(":");
132+
int index = password.indexOf(":");
133133
if (index >= 0) {
134134
password = password.substring(index + 1);
135135
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -91,6 +91,28 @@ public void testOverrideUrlRedisConfiguration() throws Exception {
9191
.isEqualTo(true);
9292
}
9393

94+
@Test
95+
public void testPasswordInUrlWithColon() {
96+
load("spring.redis.url:redis://:pass:word@example:33");
97+
assertThat(this.context.getBean(JedisConnectionFactory.class).getHostName())
98+
.isEqualTo("example");
99+
assertThat(this.context.getBean(JedisConnectionFactory.class).getPort())
100+
.isEqualTo(33);
101+
assertThat(this.context.getBean(JedisConnectionFactory.class).getPassword())
102+
.isEqualTo("pass:word");
103+
}
104+
105+
@Test
106+
public void testPasswordInUrlStartsWithColon() {
107+
load("spring.redis.url:redis://user::pass:word@example:33");
108+
assertThat(this.context.getBean(JedisConnectionFactory.class).getHostName())
109+
.isEqualTo("example");
110+
assertThat(this.context.getBean(JedisConnectionFactory.class).getPort())
111+
.isEqualTo(33);
112+
assertThat(this.context.getBean(JedisConnectionFactory.class).getPassword())
113+
.isEqualTo(":pass:word");
114+
}
115+
94116
@Test
95117
public void testRedisConfigurationWithPool() throws Exception {
96118
load("spring.redis.host:foo", "spring.redis.pool.max-idle:1");

0 commit comments

Comments
 (0)