Skip to content
Merged
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
7 changes: 7 additions & 0 deletions src/main/java/org/codejive/properties/PropertiesParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ private void addChar(int ch) throws IOException {
if (ch == '\\') {
hasEscapes = true;
int ch2 = readChar();
if (isEof(ch2)) {
// A backslash at the end of the input escapes nothing
return;
}
str.append((char) ch2);
if (ch2 == 'u') {
for (int i = 0; i < 4; i++) {
Expand Down Expand Up @@ -315,6 +319,9 @@ public static String unescape(String escape) {
for (int i = 0; i < escape.length(); i++) {
char ch = escape.charAt(i);
if (ch == '\\') {
if (i == escape.length() - 1) {
break;
}
ch = escape.charAt(++i);
switch (ch) {
case 't':
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/org/codejive/properties/TestPropertiesParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,16 @@ void testMissingSeparatorAndValueAtEof() throws IOException {
new Token(Type.SEPARATOR, ""),
new Token(Type.VALUE, ""));
}

@Test
void testBackslashAtEof() throws IOException {
List<Token> tokens =
PropertiesParser.tokens(new StringReader("foo=bar\\")).collect(Collectors.toList());

assertThat(tokens)
.containsExactly(
new Token(Type.KEY, "foo"),
new Token(Type.SEPARATOR, "="),
new Token(Type.VALUE, "bar\\", "bar"));
}
}
Loading