Skip to content

Escape backslashes in source string before loading properties #3172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
* @author John Blum
* @author Sorokin Evgeniy
* @author Marcin Grzejszczak
* @author JongJun Kim
*/
public abstract class Converters {

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

Properties info = new Properties();

try (StringReader stringReader = new StringReader(source)) {
String sourceToLoad = source.replace("\\", "\\\\");
try (StringReader stringReader = new StringReader(sourceToLoad)) {
info.load(stringReader);
} catch (Exception ex) {
throw new RedisSystemException("Cannot read Redis info", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @author Mark Paluch
* @author Sorokin Evgeniy
* @author Marcin Grzejszczak
* @author JongJun Kim
*/
class ConvertersUnitTests {

Expand Down Expand Up @@ -77,6 +78,13 @@ class ConvertersUnitTests {

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";

private static final String WINDOWS_INFO_RESPONSE = "# Server\r\n" //
+ "redis_version:3.0.504\r\n" //
+ "redis_mode:standalone\r\n" //
+ "os:Windows\r\n" //
+ "executable:C:\\Program Files\\Redis\\redis-server.exe\r\n" //
+ "config_file:C:\\Program Files\\Redis\\redis.windows.conf\r\n";

@Test // DATAREDIS-315
void toSetOfRedis30ClusterNodesShouldConvertSingleStringNodesResponseCorrectly() {

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

return Stream.concat(regular, weird);
}

@Test // GH-3099
void toPropertiesShouldParseInfoStringWithWindowsPaths() {

assertThat(Converters.toProperties(WINDOWS_INFO_RESPONSE)).containsEntry("executable",
"C:\\Program Files\\Redis\\redis-server.exe");
}
}