11package path_matcher
22
33import (
4- "fmt "
4+ "os "
55 "path/filepath"
66 "strings"
77
88 "github.com/bmatcuk/doublestar/v4"
99
1010 "github.com/werf/common-go/pkg/util"
11+ "github.com/werf/logboek"
12+ )
13+
14+ const (
15+ specialCharError = "The specified glob pattern contains special characters '?[{' that need to be properly used or escaped with '\\ \\ '."
1116)
1217
1318func matchGlobs (pathPart string , globs []string ) (inProgressGlobs , matchedGlobs []string ) {
@@ -74,11 +79,14 @@ func isPathMatched(filePath, glob string) bool {
7479 util .SafeTrimGlobsAndSlashesFromFilepath (glob ),
7580 filepath .Join (util .SafeTrimGlobsAndSlashesFromFilepath (glob ), "**" , "*" ),
7681 } {
77- matched , err := doublestar .PathMatch (escapeGlobSpecials ( g ) , filePath )
82+ matched , err := doublestar .PathMatch (g , filePath )
7883 if err != nil {
79- panic (fmt .Sprintf ("failed to match path %q with glob %q: %v" , filePath , g , err ))
84+ logboek .Error ().LogF ("Failed to match path %q with glob %q: %v\n " , filePath , g , err )
85+ if strings .ContainsAny (g , "?[{" ) {
86+ logboek .Error ().LogF ("%s\n " , specialCharError )
87+ }
88+ os .Exit (1 )
8089 }
81-
8290 if matched {
8391 return true
8492 }
@@ -87,18 +95,6 @@ func isPathMatched(filePath, glob string) bool {
8795 return false
8896}
8997
90- func escapeGlobSpecials (path string ) string {
91- specials := `?[]{}!\\`
92- var b strings.Builder
93- for _ , r := range path {
94- if strings .ContainsRune (specials , r ) {
95- b .WriteRune ('\\' )
96- }
97- b .WriteRune (r )
98- }
99- return b .String ()
100- }
101-
10298func formatPaths (paths []string ) []string {
10399 var result []string
104100 for _ , path := range paths {
0 commit comments