@@ -52,40 +52,47 @@ func isGlobCandidate(str string) bool {
5252}
5353
5454func (patternMatcher * PatternMatcher ) Add (pattern string , val interface {}, position int ) error {
55+ // Determine pattern type based on wildcards and special characters
5556 leadingStar := strings .HasPrefix (pattern , "*" )
5657 trailingStar := strings .HasSuffix (pattern , "*" )
5758 exact := strings .HasPrefix (pattern , "=" )
5859 patternType := PatternTypeNone
60+
61+ // Check for glob pattern with wildcard characters
5962 if isGlobCandidate (pattern ) {
6063 patternType = PatternTypePattern
61- _ , err := filepath .Match (pattern , "example.com" )
64+ _ , err := filepath .Match (pattern , "example.com" ) // Validate pattern syntax
6265 if len (pattern ) < 2 || err != nil {
6366 return fmt .Errorf ("Syntax error in block rules at pattern %d" , position )
6467 }
6568 } else if leadingStar && trailingStar {
69+ // Substring match (*contains*)
6670 patternType = PatternTypeSubstring
6771 if len (pattern ) < 3 {
6872 return fmt .Errorf ("Syntax error in block rules at pattern %d" , position )
6973 }
70- pattern = pattern [1 : len (pattern )- 1 ]
74+ pattern = pattern [1 : len (pattern )- 1 ] // Remove stars
7175 } else if trailingStar {
76+ // Prefix match (starts*)
7277 patternType = PatternTypePrefix
7378 if len (pattern ) < 2 {
7479 return fmt .Errorf ("Syntax error in block rules at pattern %d" , position )
7580 }
76- pattern = pattern [:len (pattern )- 1 ]
81+ pattern = pattern [:len (pattern )- 1 ] // Remove trailing star
7782 } else if exact {
83+ // Exact match (=example.com)
7884 patternType = PatternTypeExact
7985 if len (pattern ) < 2 {
8086 return fmt .Errorf ("Syntax error in block rules at pattern %d" , position )
8187 }
82- pattern = pattern [1 :]
88+ pattern = pattern [1 :] // Remove = prefix
8389 } else {
90+ // Default: suffix match (*ends or .ends)
8491 patternType = PatternTypeSuffix
8592 if leadingStar {
86- pattern = pattern [1 :]
93+ pattern = pattern [1 :] // Remove leading star
8794 }
88- pattern = strings .TrimPrefix (pattern , "." )
95+ pattern = strings .TrimPrefix (pattern , "." ) // Remove leading dot if present
8996 }
9097 if len (pattern ) == 0 {
9198 dlog .Errorf ("Syntax error in block rule at line %d" , position )
0 commit comments