Skip to content

Commit

Permalink
Don't allow [] characters in patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
hmarr committed Mar 28, 2021
1 parent 3745468 commit 8e6721a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func isAlphanumeric(ch rune) bool {
// isPatternChar matches characters that are allowed in patterns
func isPatternChar(ch rune) bool {
switch ch {
case '*', '?', '.', '/', '@', '_', '+', '-', '[', ']', '\\':
case '*', '?', '.', '/', '@', '_', '+', '-', '\\':
return true
}
return isAlphanumeric(ch)
Expand Down
9 changes: 7 additions & 2 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func TestParseRule(t *testing.T) {
},
{
name: "complex patterns",
rule: "[d]?r/* @user",
rule: "d?r/* @user",
expected: Rule{
pattern: mustBuildPattern(t, "[d]?r/*"),
pattern: mustBuildPattern(t, "d?r/*"),
Owners: []Owner{{Value: "user", Type: "username"}},
},
},
Expand Down Expand Up @@ -92,6 +92,11 @@ func TestParseRule(t *testing.T) {
rule: "file.{txt @user",
err: "unexpected character '{' at position 6",
},
{
name: "patterns with brackets",
rule: "file.[cC] @user",
err: "unexpected character '[' at position 6",
},
{
name: "malformed owners",
rule: "file.txt missing-at-sign",
Expand Down

0 comments on commit 8e6721a

Please sign in to comment.