Escape backslashes in source string before loading properties
Overview
This PR resolves an IllegalArgumentException that occurs when parsing the Redis INFO command response in a Windows environment. This issue is described in GitHub issue #3099 and is also related to the previously closed issue #1281.
The Problem
On Windows, the Redis INFO command output can contain values with backslashes (\), such as the path to the executable (executable:C:\Users\...). The Converters.toProperties(String) method in spring-data-redis uses java.util.Properties.load() internally to parse this response.
However, Properties.load() treats the backslash as a special escape character. Consequently, it misinterprets sequences like \u in a file path as a Unicode escape sequence, leading to an IllegalArgumentException. This poses a challenge for developers working in a Windows environment.
The Solution
To address this while preserving the existing code structure, I've introduced a minimal change to the Converters.toProperties(String) method. Before calling Properties.load(), all backslashes (\) in the input string are replaced with double backslashes (\\).
Before:
try (StringReader stringReader = new StringReader(source)) {
info.load(stringReader);
}
After:
String sourceToLoad = source.replace("\\", "\\\\");
try (StringReader stringReader = new StringReader(sourceToLoad)) {
info.load(stringReader);
}
This simple change ensures that Properties.load() correctly interprets backslashes as literal characters, preventing any parsing errors. The fix is applied to the Converters class, which is shared by both Jedis and Lettuce client implementations, resolving the issue for both drivers.
Related Issue
- Fixes #3099
- [x] You have read the Spring Data contribution guidelines.
- [x] You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
- [x] You submit test cases (unit or integration tests) that back your changes.
- [x] You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).