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
6 changes: 6 additions & 0 deletions src/main/java/org/codejive/properties/PropertiesParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ private void addChar(int ch) throws IOException {
}
} else {
readEol(ch2);
if (isEol(ch2)) {
// A line continuation also skips the leading whitespace of the next line
while (isWhitespaceChar(peekChar())) {
str.append((char) readChar());
}
}
}
} else {
readEol(ch);
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/codejive/properties/TestProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,14 @@ void testCommentEndingWithBackslash() throws IOException {
assertThat(p).containsEntry("alpha", "1");
}

@Test
void testLineContinuationFollowedByIndentation() throws IOException {
Properties p =
Properties.loadProperties(new StringReader("long.\\\n key=1\n \\\n beta=2\n"));

assertThat(p).containsOnly(entry("long.key", "1"), entry("beta", "2"));
}

@Test
void testPutNewTest2() throws IOException, URISyntaxException {
Path f = getResource("/test2.properties");
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/codejive/properties/TestPropertiesParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ void testBackslashesInComment() throws IOException {
new Token(Type.VALUE, "bar"));
}

@Test
void testLineContinuationInKey() throws IOException {
List<Token> tokens =
PropertiesParser.tokens(new StringReader("key\\\n part=value"))
.collect(Collectors.toList());

assertThat(tokens)
.containsExactly(
new Token(Type.KEY, "key\\\n part", "keypart"),
new Token(Type.SEPARATOR, "="),
new Token(Type.VALUE, "value"));
}

@Test
void testEmptySeparatorAndValueAtEof() throws IOException {
List<Token> tokens =
Expand Down
Loading