diff --git a/pkg/version/constraint_test.go b/pkg/version/constraint_test.go index 3108a7b..94caa67 100644 --- a/pkg/version/constraint_test.go +++ b/pkg/version/constraint_test.go @@ -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) { diff --git a/pkg/version/version.go b/pkg/version/version.go index 5ffb998..7735d6a 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -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.