Skip to content

Commit d31d534

Browse files
authored
Don't let non-parameterized capture groups truncate comment (#13)
`.` is considered a captured group
1 parent 7e48566 commit d31d534

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

forbidigo/patterns.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ func parse(ptrn string) (*pattern, error) {
2929
// is present.
3030
func extractComment(re *syntax.Regexp) string {
3131
for _, sub := range re.Sub {
32+
subStr := sub.String()
33+
if strings.HasPrefix(subStr, "#") {
34+
return strings.TrimSpace(strings.TrimPrefix(sub.String(), "#"))
35+
}
3236
if len(sub.Sub) > 0 {
3337
if comment := extractComment(sub); comment != "" {
3438
return comment
3539
}
3640
}
37-
subStr := sub.String()
38-
if strings.HasPrefix(subStr, "#") {
39-
return strings.TrimSpace(strings.TrimPrefix(subStr, "#"))
40-
}
4141
}
4242
return ""
4343
}

0 commit comments

Comments
 (0)