Skip to content

Commit

Permalink
Update CODEOWNERS parser to not log errors on comments with leading w…
Browse files Browse the repository at this point in the history
…hitespace
  • Loading branch information
nikita-tkachenko-datadog committed Feb 6, 2025
1 parent 986e87d commit d5d5a40
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
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]",
"",
" ",
]
}
}

0 comments on commit d5d5a40

Please sign in to comment.