diff --git a/src/main/java/org/codejive/properties/PropertiesParser.java b/src/main/java/org/codejive/properties/PropertiesParser.java index aa14fd6..c9fc70c 100644 --- a/src/main/java/org/codejive/properties/PropertiesParser.java +++ b/src/main/java/org/codejive/properties/PropertiesParser.java @@ -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); diff --git a/src/test/java/org/codejive/properties/TestProperties.java b/src/test/java/org/codejive/properties/TestProperties.java index b53273a..5570a79 100644 --- a/src/test/java/org/codejive/properties/TestProperties.java +++ b/src/test/java/org/codejive/properties/TestProperties.java @@ -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"); diff --git a/src/test/java/org/codejive/properties/TestPropertiesParser.java b/src/test/java/org/codejive/properties/TestPropertiesParser.java index 79d3d4c..e9ab7cc 100644 --- a/src/test/java/org/codejive/properties/TestPropertiesParser.java +++ b/src/test/java/org/codejive/properties/TestPropertiesParser.java @@ -123,6 +123,19 @@ void testBackslashesInComment() throws IOException { new Token(Type.VALUE, "bar")); } + @Test + void testLineContinuationInKey() throws IOException { + List 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 tokens =