Skip to content

Commit

Permalink
Fix parsing and comparing versions with build information (#8)
Browse files Browse the repository at this point in the history
fixes #7
  • Loading branch information
bpfoster authored Nov 5, 2024
1 parent cf8a8d2 commit 1951e80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/version/constraint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ func TestVersion_Check(t *testing.T) {
{"> 1.0 < 1.2 || >3.0, <4.0", "4.2", false},
{"^0.2 || ^1", "1.8.0", true},
{"^0.2, ^1", "1.8.0", false},

// Build identifiers
{">= 1.0.0, < 1.2.0+security-01", "1.0.0", true},
{">= 1.0.0, < 1.2.0+security-01", "1.2.0", false},
{">= 1.0.0, <= 1.2.0+security-01", "1.2.0", true},
{">= 1.0.0, < 1.2.0+security-01", "1.3.0", false},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%s %s", tt.version, tt.constraint), func(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ const (
// The raw regular expression string used for testing the validity of a version.
regex = `v?([0-9]+(\.[0-9]+)*)` +
`(-([0-9]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)|(-?([A-Za-z\-~]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)))?` +
`(\+([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?` +
`?`
`(\+([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?`
)

// Version represents a single version.
Expand Down

0 comments on commit 1951e80

Please sign in to comment.