Skip to content

Commit d7cab20

Browse files
committed
Escape backslashes in source string before loading properties
Signed-off-by: belljun3395 <195850@jnu.ac.kr>
1 parent adb23d6 commit d7cab20

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/main/java/org/springframework/data/redis/connection/convert/Converters.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
* @author John Blum
6464
* @author Sorokin Evgeniy
6565
* @author Marcin Grzejszczak
66+
* @author JongJun Kim
6667
*/
6768
public abstract class Converters {
6869

@@ -107,7 +108,8 @@ public static Properties toProperties(String source) {
107108

108109
Properties info = new Properties();
109110

110-
try (StringReader stringReader = new StringReader(source)) {
111+
String sourceToLoad = source.replace("\\", "\\\\");
112+
try (StringReader stringReader = new StringReader(sourceToLoad)) {
111113
info.load(stringReader);
112114
} catch (Exception ex) {
113115
throw new RedisSystemException("Cannot read Redis info", ex);

src/test/java/org/springframework/data/redis/connection/convert/ConvertersUnitTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* @author Mark Paluch
3939
* @author Sorokin Evgeniy
4040
* @author Marcin Grzejszczak
41+
* @author JongJun Kim
4142
*/
4243
class ConvertersUnitTests {
4344

@@ -77,6 +78,13 @@ class ConvertersUnitTests {
7778

7879
private static final String CLUSTER_NODE_WITH_SINGLE_IPV4_HOSTNAME = "3765733728631672640db35fd2f04743c03119c6 10.180.0.33:11003@16379,hostname1 master - 0 1708041426947 2 connected 0-5460";
7980

81+
private static final String WINDOWS_INFO_RESPONSE = "# Server\r\n" //
82+
+ "redis_version:3.0.504\r\n" //
83+
+ "redis_mode:standalone\r\n" //
84+
+ "os:Windows\r\n" //
85+
+ "executable:C:\\Program Files\\Redis\\redis-server.exe\r\n" //
86+
+ "config_file:C:\\Program Files\\Redis\\redis.windows.conf\r\n";
87+
8088
@Test // DATAREDIS-315
8189
void toSetOfRedis30ClusterNodesShouldConvertSingleStringNodesResponseCorrectly() {
8290

@@ -367,4 +375,11 @@ static Stream<Arguments> clusterNodesEndpoints() {
367375

368376
return Stream.concat(regular, weird);
369377
}
378+
379+
@Test // GH-3099
380+
void toPropertiesShouldParseInfoStringWithWindowsPaths() {
381+
382+
assertThat(Converters.toProperties(WINDOWS_INFO_RESPONSE)).containsEntry("executable",
383+
"C:\\Program Files\\Redis\\redis-server.exe");
384+
}
370385
}

0 commit comments

Comments
 (0)