Skip to content

Commit d5d5a40

Browse files
Update CODEOWNERS parser to not log errors on comments with leading whitespace
1 parent 986e87d commit d5d5a40

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/codeowners/EntryBuilder.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,14 @@ public EntryBuilder(CharacterMatcher.Factory characterMatcherFactory, String s)
4747

4848
public @Nullable Entry parse() {
4949
try {
50-
if (c.length == 0 // empty line
51-
|| c[0] == '#' // comment
52-
|| c[0] == '[') { // section header
50+
// skip trailing whitespace
51+
while (offset < c.length && Character.isWhitespace(c[offset])) {
52+
offset++;
53+
}
54+
55+
if (offset == c.length // empty line
56+
|| c[offset] == '#' // comment
57+
|| c[offset] == '[') { // section header
5358
return null;
5459
}
5560

dd-java-agent/agent-ci-visibility/src/test/groovy/datadog/trace/civisibility/codeowners/EntryBuilderTest.groovy

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,25 @@ class EntryBuilderTest extends Specification {
154154
return result.toString()
155155
}
156156

157-
def "test invalid range parsing"() {
157+
def "test invalid entry parsing: #entry"() {
158158
setup:
159159
def matcherFactory = new CharacterMatcher.Factory()
160160

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

164164
then:
165-
entry == null
165+
parsedEntry == null
166+
167+
where:
168+
entry << [
169+
"token[z-a] owner",
170+
"# comment",
171+
" # comment with a leading space",
172+
"[section header]",
173+
" [section header with a leading space]",
174+
"",
175+
" ",
176+
]
166177
}
167178
}

0 commit comments

Comments
 (0)