Skip to content

Commit

Permalink
Add empty glob error when no files match
Browse files Browse the repository at this point in the history
  • Loading branch information
gantony committed Dec 20, 2024
1 parent dcdbc28 commit ca5863e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/seclang/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ type Parser struct {
// It will return error if any directive fails to parse
// or the file does not exist.
// If the path contains a *, it will be expanded to all
// files in the directory matching the pattern
// files in the directory matching the pattern.
// It will rereturn an error if there are no files matching the pattern.
func (p *Parser) FromFile(profilePath string) error {
originalDir := p.currentDir

Expand All @@ -45,6 +46,9 @@ func (p *Parser) FromFile(profilePath string) error {
if err != nil {
return fmt.Errorf("failed to glob: %s", err.Error())
}
if len(files) == 0 {
return fmt.Errorf("empty glob: %s does not match any file", profilePath)
}
} else {
files = append(files, profilePath)
}
Expand Down
5 changes: 5 additions & 0 deletions internal/seclang/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func TestLoadConfigurationFile(t *testing.T) {
if err != nil {
t.Errorf("unexpected error: %s", err.Error())
}

err = p.FromFile("./testdata/glob/*.comf")
if err == nil {
t.Errorf("expected an error as glob does not match any file")
}
}

// Connectors are supporting embedding github.com/corazawaf/coraza-coreruleset to ease CRS integration
Expand Down

0 comments on commit ca5863e

Please sign in to comment.