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
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ public EntryBuilder(CharacterMatcher.Factory characterMatcherFactory, String s)

public @Nullable Entry parse() {
try {
if (c.length == 0 // empty line
|| c[0] == '#' // comment
|| c[0] == '[') { // section header
// skip trailing whitespace
while (offset < c.length && Character.isWhitespace(c[offset])) {
offset++;
}

if (offset == c.length // empty line
|| c[offset] == '#' // comment
|| c[offset] == '[') { // section header
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,25 @@ class EntryBuilderTest extends Specification {
return result.toString()
}

def "test invalid range parsing"() {
def "test invalid entry parsing: #entry"() {
setup:
def matcherFactory = new CharacterMatcher.Factory()

when:
def entry = new EntryBuilder(matcherFactory, "token[z-a] owner").parse()
def parsedEntry = new EntryBuilder(matcherFactory, entry).parse()

then:
entry == null
parsedEntry == null

where:
entry << [
"token[z-a] owner",
"# comment",
" # comment with a leading space",
"[section header]",
" [section header with a leading space]",
"",
" ",
]
}
}
Loading