Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
Fix regex matching for releases to be properly anchored by ^ and $
Browse files Browse the repository at this point in the history
  • Loading branch information
John Esmet committed Aug 1, 2019
1 parent 8d0129b commit e5d9690
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,12 @@ func MapSliceRegexMatch(mapSlice yaml.MapSlice, key string) (interface{}, error)
if !ok {
return nil, fmt.Errorf("Could not parse key as string: %v", item.Key)
}
matched, err := regexp.MatchString(regex, key)
// We definitely do not want to match substrings, so we anchor the provided
// regex with ^ at the front and $ at the back.
wholeRegex := fmt.Sprintf("^%v$", regex)
matched, err := regexp.MatchString(wholeRegex, key)
if err != nil {
return nil, fmt.Errorf("Failed to evaluate regex %v over key %v: %v", key, regex, err)
return nil, fmt.Errorf("Failed to evaluate regex %v over key %v: %v", key, wholeRegex, err)
}

if !matched {
Expand Down

0 comments on commit e5d9690

Please sign in to comment.