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
3 changes: 2 additions & 1 deletion src/main/java/org/codejive/properties/PropertiesParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ private int readChar() throws IOException {

private void addChar(int ch) throws IOException {
str.append((char) ch);
if (ch == '\\') {
// Comments have no escapes or line continuations
if (ch == '\\' && state != Type.COMMENT) {
hasEscapes = true;
int ch2 = readChar();
str.append((char) ch2);
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 @@ -822,6 +822,14 @@ void testPutAtInvalidPosition() throws IOException {
assertThat(p).containsEntry("middle", "3");
}

@Test
void testCommentEndingWithBackslash() throws IOException {
Properties p =
Properties.loadProperties(new StringReader("# temp dir: C:\\temp\\\nalpha=1\n"));

assertThat(p).containsEntry("alpha", "1");
}

@Test
void testPutNewTest2() throws IOException, URISyntaxException {
Path f = getResource("/test2.properties");
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/codejive/properties/TestPropertiesParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ void testStringify() throws IOException {
assertThat(props2).isEqualTo(props);
}

@Test
void testBackslashesInComment() throws IOException {
List<Token> tokens =
PropertiesParser.tokens(new StringReader("# C:\\users\\\nfoo=bar"))
.collect(Collectors.toList());

assertThat(tokens)
.containsExactly(
new Token(Type.COMMENT, "# C:\\users\\"),
new Token(Type.WHITESPACE, "\n"),
new Token(Type.KEY, "foo"),
new Token(Type.SEPARATOR, "="),
new Token(Type.VALUE, "bar"));
}

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