Skip to content

Commit 538b68e

Browse files
Update file parsing to handle lines with only whitespace.
This commit updates file parsing so that lines that contain solely whitespace (as defined by by Unicode) are ignored. It's fairly common for people to accidentally create CODEOWNERS files with lines containing solely whitespace, and as it's semantically meaningless, it's better to ignore them then raise an error.
1 parent bd19ed7 commit 538b68e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

example_test.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
)
99

1010
func Example() {
11-
f := bytes.NewBufferString("src/**/*.c @acme/c-developers")
11+
f := bytes.NewBufferString(`src/**/*.c @acme/c-developers
12+
# The following line should be ignored; it contains only spaces and tabs` +
13+
" \t\nsrc/**/*.go @acme/go-developers")
1214
ruleset, err := codeowners.ParseFile(f)
1315
if err != nil {
1416
panic(err)
@@ -19,9 +21,13 @@ func Example() {
1921

2022
match, err = ruleset.Match("src/foo.rs")
2123
fmt.Println(match)
24+
25+
match, err = ruleset.Match("src/go/bar/bar.go")
26+
fmt.Println(match.Owners)
2227
// Output:
2328
// [@acme/c-developers]
2429
// <nil>
30+
// [@acme/go-developers]
2531
}
2632

2733
func ExampleParseFile() {

parse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func ParseFile(f io.Reader) (Ruleset, error) {
3030
line := scanner.Text()
3131

3232
// Ignore blank lines and comments
33-
if len(line) == 0 || line[0] == '#' {
33+
if len(strings.TrimSpace(line)) == 0 || line[0] == '#' {
3434
continue
3535
}
3636

0 commit comments

Comments
 (0)