Skip to content

Commit

Permalink
fix issue with underscores in match groups
Browse files Browse the repository at this point in the history
  • Loading branch information
choffmeister committed Dec 9, 2021
1 parent b7e3c7b commit 7b483f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type SemverExtractStrategy struct {
AllowPrereleases bool
}

var extractPattern = regexp.MustCompile(`<([a-zA-Z0-9\-]+)>`)
var extractPattern = regexp.MustCompile(`<([a-zA-Z0-9\-_]+)>`)

func (p Policy) Parse(version string, prefix string, suffix string) (*[]string, error) {
unpackedVersion := version
Expand Down
14 changes: 14 additions & 0 deletions internal/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ func TestPolicyParse(t *testing.T) {
if assert.NoError(t, err) {
assert.Nil(t, actual)
}

p4 := Policy{
Pattern: regexp.MustCompile(`^(?P<foo_bar>\d+)$`),
Extracts: []Extract{
{
Value: "<foo_bar>",
Strategy: NumericExtractStrategy{},
},
},
}
actual, err = p4.Parse("123", "", "")
if assert.NoError(t, err) {
assert.Equal(t, &[]string{"123"}, actual)
}
}

func TestPolicyFilterAndSort(t *testing.T) {
Expand Down

0 comments on commit 7b483f8

Please sign in to comment.