Skip to content

Commit 8d1b6cb

Browse files
committed
refactor: changed how comment blocks are handled
We now consider all consecutive comment lines to be part of the same block, regardless of the comment prefix used for each line. (So no longer do we take a block to end when the comment prefix changes)
1 parent 36fb7a7 commit 8d1b6cb

File tree

3 files changed

+1
-9
lines changed

3 files changed

+1
-9
lines changed

src/main/java/org/codejive/properties/Properties.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,8 @@ private List<Integer> findCommentLines(int idx) {
269269
idx--;
270270
}
271271
// Now find the first line of the comment block
272-
int commentSym = -1;
273272
PropertiesParser.Token token;
274273
while (idx >= 0 && (token = tokens.get(idx)).getType() == PropertiesParser.Type.COMMENT) {
275-
if (commentSym != -1 && commentSym != token.raw.charAt(0)) {
276-
// Comment doesn't start with the same comment symbol, so the block ends here
277-
break;
278-
} else {
279-
commentSym = token.raw.charAt(0);
280-
}
281274
result.add(0, idx);
282275
// Skip any preceding whitespace making sure to stop at EOL
283276
while (--idx >= 0 && !tokens.get(idx).isEol()) {}

src/test/java/org/codejive/properties/TestProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void testGetComment() throws IOException, URISyntaxException {
6868
Properties p = Properties.loadProperties(getResource("/test.properties"));
6969
assertThat(p.getComment("one"), contains("! comment3"));
7070
assertThat(p.getComment("two"), empty());
71-
assertThat(p.getComment("three"), contains("! and a comment", "! block"));
71+
assertThat(p.getComment("three"), contains("# another comment", "! and a comment", "! block"));
7272
}
7373

7474
@Test

src/test/resources/test-comment.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ one=simple
77
# line
88
# comment
99
two=value containing spaces
10-
# another comment
1110
three=and escapes\n\t\r\f
1211
\ with\ spaces = everywhere
1312
altsep:value

0 commit comments

Comments
 (0)