Skip to content

Commit 06d1caa

Browse files
committed
permit leading and trailing whitespace
1 parent 477e3fd commit 06d1caa

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

parse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func ParseFile(f io.Reader, options ...parseOption) (Ruleset, error) {
108108
lineNo := 0
109109
for scanner.Scan() {
110110
lineNo++
111-
line := scanner.Text()
111+
line := strings.TrimSpace(scanner.Text())
112112

113113
// Ignore blank lines and comments
114114
if len(line) == 0 || line[0] == '#' {

parse_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ func TestParseFile(t *testing.T) {
4747
},
4848
},
4949
},
50+
{
51+
name: "with blank lines with whitespace",
52+
contents: "\nfile.txt @user\n \t\nfile2.txt @org/team\n",
53+
expected: Ruleset{
54+
{
55+
pattern: mustBuildPattern(t, "file.txt"),
56+
Owners: []Owner{{Value: "user", Type: "username"}},
57+
LineNumber: 2,
58+
},
59+
{
60+
pattern: mustBuildPattern(t, "file2.txt"),
61+
Owners: []Owner{{Value: "org/team", Type: "team"}},
62+
LineNumber: 4,
63+
},
64+
},
65+
},
5066

5167
// Error cases
5268
{

0 commit comments

Comments
 (0)