Skip to content

Commit 5a2a272

Browse files
committed
allow pipe and curly braces in patterns
1 parent fd957bb commit 5a2a272

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

parse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func isAlphanumeric(ch rune) bool {
257257
// isPatternChar matches characters that are allowed in patterns
258258
func isPatternChar(ch rune) bool {
259259
switch ch {
260-
case '*', '?', '.', '/', '@', '_', '+', '-', '\\', '(', ')':
260+
case '*', '?', '.', '/', '@', '_', '+', '-', '\\', '(', ')', '|', '{', '}':
261261
return true
262262
}
263263
return isAlphanumeric(ch)

parse_test.go

+40-5
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,53 @@ func TestParseRule(t *testing.T) {
233233
Comment: "",
234234
},
235235
},
236+
{
237+
name: "pattern with pipe character '|'",
238+
rule: "foo|bar|baz @org/team",
239+
expected: Rule{
240+
pattern: mustBuildPattern(t, "foo|bar|baz"),
241+
Owners: []Owner{{Value: "org/team", Type: "team"}},
242+
},
243+
},
244+
{
245+
name: "pattern with left curly brace '{'",
246+
rule: "foo{bar.txt @org/team",
247+
expected: Rule{
248+
pattern: mustBuildPattern(t, "foo{bar.txt"),
249+
Owners: []Owner{{Value: "org/team", Type: "team"}},
250+
},
251+
},
252+
{
253+
name: "pattern with right curly brace '}'",
254+
rule: "foo}bar.txt @org/team",
255+
expected: Rule{
256+
pattern: mustBuildPattern(t, "foo}bar.txt"),
257+
Owners: []Owner{{Value: "org/team", Type: "team"}},
258+
},
259+
},
260+
{
261+
name: "pattern with curly braces '{' and '}'",
262+
rule: "foo{bar}.txt @org/team",
263+
expected: Rule{
264+
pattern: mustBuildPattern(t, "foo{bar}.txt"),
265+
Owners: []Owner{{Value: "org/team", Type: "team"}},
266+
},
267+
},
268+
{
269+
name: "pattern with curly braces and pipe character",
270+
rule: "foo|{bar}.txt @org/team",
271+
expected: Rule{
272+
pattern: mustBuildPattern(t, "foo|{bar}.txt"),
273+
Owners: []Owner{{Value: "org/team", Type: "team"}},
274+
},
275+
},
236276

237277
// Error cases
238278
{
239279
name: "empty rule",
240280
rule: "",
241281
err: "unexpected end of rule",
242282
},
243-
{
244-
name: "malformed patterns",
245-
rule: "file.{txt @user",
246-
err: "unexpected character '{' at position 6",
247-
},
248283
{
249284
name: "patterns with brackets",
250285
rule: "file.[cC] @user",

0 commit comments

Comments
 (0)