Skip to content
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 @@ -15,7 +15,6 @@
*/
package org.springframework.data.redis.connection.convert;

import java.io.StringReader;
import java.nio.ByteBuffer;
import java.time.Duration;
import java.util.*;
Expand All @@ -30,7 +29,6 @@
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Metric;
import org.springframework.data.geo.Metrics;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.RedisClusterNode;
Expand Down Expand Up @@ -106,10 +104,15 @@ public static Properties toProperties(String source) {

Properties info = new Properties();

try (StringReader stringReader = new StringReader(source)) {
info.load(stringReader);
} catch (Exception ex) {
throw new RedisSystemException("Cannot read Redis info", ex);
for (String line : source.split("\\r?\\n")) {
String trimmed = line.trim();
if (trimmed.isEmpty() || trimmed.startsWith("#")) {
continue;
}
int colonIndex = trimmed.indexOf(':');
if (colonIndex > 0) {
info.setProperty(trimmed.substring(0, colonIndex).trim(), trimmed.substring(colonIndex + 1).trim());
}
}

return info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
*/
package org.springframework.data.redis.connection.convert;

import java.io.StringReader;
import java.util.Properties;

import org.springframework.core.convert.converter.Converter;
import org.springframework.data.redis.RedisSystemException;

/**
* Converts Strings to {@link Properties}
* Converts Strings in Redis {@code INFO} / {@code CLUSTER INFO} key:value format to {@link Properties}.
* <p>
* Unlike {@link Properties#load}, this converter does not interpret escape sequences (e.g. {@code \u}) so that values
* containing backslashes — such as Windows-style file paths emitted by Redis on Windows — are preserved verbatim.
*
* @author Jennifer Hickey
* @author Christoph Strobl
Expand All @@ -31,13 +32,6 @@ public class StringToPropertiesConverter implements Converter<String, Properties

@Override
public Properties convert(String source) {

Properties info = new Properties();
try (StringReader stringReader = new StringReader(source)) {
info.load(stringReader);
} catch (Exception ex) {
throw new RedisSystemException("Cannot read Redis info", ex);
}
return info;
return Converters.toProperties(source);
}
}
Loading