Skip to content

Commit 8e6721a

Browse files
committed
Don't allow [] characters in patterns
1 parent 3745468 commit 8e6721a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

parse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func isAlphanumeric(ch rune) bool {
171171
// isPatternChar matches characters that are allowed in patterns
172172
func isPatternChar(ch rune) bool {
173173
switch ch {
174-
case '*', '?', '.', '/', '@', '_', '+', '-', '[', ']', '\\':
174+
case '*', '?', '.', '/', '@', '_', '+', '-', '\\':
175175
return true
176176
}
177177
return isAlphanumeric(ch)

parse_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ func TestParseRule(t *testing.T) {
5252
},
5353
{
5454
name: "complex patterns",
55-
rule: "[d]?r/* @user",
55+
rule: "d?r/* @user",
5656
expected: Rule{
57-
pattern: mustBuildPattern(t, "[d]?r/*"),
57+
pattern: mustBuildPattern(t, "d?r/*"),
5858
Owners: []Owner{{Value: "user", Type: "username"}},
5959
},
6060
},
@@ -92,6 +92,11 @@ func TestParseRule(t *testing.T) {
9292
rule: "file.{txt @user",
9393
err: "unexpected character '{' at position 6",
9494
},
95+
{
96+
name: "patterns with brackets",
97+
rule: "file.[cC] @user",
98+
err: "unexpected character '[' at position 6",
99+
},
95100
{
96101
name: "malformed owners",
97102
rule: "file.txt missing-at-sign",

0 commit comments

Comments
 (0)