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 @@ -154,7 +154,12 @@ protected String escape(final String key) {
if (c >= ' ' && illegalChars.indexOf(c) < 0) {
buffer.append(c);
} else {
buffer.append("%" + Integer.toHexString(c).toUpperCase());
final String hex = Integer.toHexString(c).toUpperCase();
buffer.append('%');
if (hex.length() < 2) {
buffer.append('0');
}
buffer.append(hex);
}
}
return buffer.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ public void testEscapesPercentageWhileExtractingAKey() {
assertEquals("%guilherme", strategy.extractKey("string@%25guilherme.xml"));
}

public void testEscapesControlCharacterWithTwoHexDigits() {
final FilePersistenceStrategy<String, String> strategy = new FilePersistenceStrategy<String, String>(baseDir);
assertEquals("string@%09guilherme.xml", strategy.getName("\tguilherme"));
assertEquals("\tguilherme", strategy.extractKey("string@%09guilherme.xml"));
}

public void testRoundTripsKeyWithControlCharacter() {
final FilePersistenceStrategy<String, String> strategy = new FilePersistenceStrategy<String, String>(baseDir);
assertEquals("\nguilherme", strategy.extractKey(strategy.getName("\nguilherme")));
}

public void testDistinctKeysDoNotShareAFilename() {
final FilePersistenceStrategy<String, String> strategy = new FilePersistenceStrategy<String, String>(baseDir);
assertFalse(strategy.getName("\u0012").equals(strategy.getName("\u0001" + "2")));
}

public void testEscapesNullKeyWhileGettingAFileName() {
final FilePersistenceStrategy<String, String> strategy = new FilePersistenceStrategy<String, String>(baseDir);
assertEquals("null@null.xml", strategy.getName(null));
Expand Down