Skip to content

Extend Allowed Version Formats #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ var (
// The raw regular expression string used for testing the validity
// of a version.
const (
VersionRegexpRaw string = `v?([0-9]+(\.[0-9]+)*?)` +
VersionRegexpRaw string = `[vV]?([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\-~]+)*))?` +
`([\+\.\-~]g[0-9A-Fa-f]{10}$)?` +
`?`

// SemverRegexpRaw requires a separator between version and prerelease
Expand Down
29 changes: 16 additions & 13 deletions version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@ func TestNewVersion(t *testing.T) {
version string
err bool
}{
{"", true},
{"1.2.3", false},
{"1.0", false},
{"1", false},
{"1.2.beta", true},
{"1.21.beta", true},
{"foo", true},
{"1.2-5", false},
{"1.2-beta.5", false},
{"\n1.2", true},
{"1.2.0-x.Y.0+metadata", false},
{"1.2.0-x.Y.0+metadata-width-hypen", false},
{"1.2.3-rc1-with-hypen", false},
Expand All @@ -29,11 +24,19 @@ func TestNewVersion(t *testing.T) {
{"1.2.0-X-1.2.0+metadata~dist", false},
{"1.2.3.4-rc1-with-hypen", false},
{"1.2.3.4", false},
{"v1.2.3", false},
{"foo1.2.3", true},
{"V1.2.3", false},
{"1.7rc2", false},
{"v1.7rc2", false},
{"1.0-", false},
{"v1.0-", false},
{"2.28.0.618+gf4bc123cb7", false},
{"1.13.0+dev-545-gb3b1c081b", false},
{"2.28.0.618.gf4bc123cb7", false},
{"", true},
{"1.2.beta", true},
{"1.21.beta", true},
{"foo", true},
{"\n1.2", true},
{"foo1.2.3", true},
}

for _, tc := range cases {
Expand All @@ -51,16 +54,11 @@ func TestNewSemver(t *testing.T) {
version string
err bool
}{
{"", true},
{"1.2.3", false},
{"1.0", false},
{"1", false},
{"1.2.beta", true},
{"1.21.beta", true},
{"foo", true},
{"1.2-5", false},
{"1.2-beta.5", false},
{"\n1.2", true},
{"1.2.0-x.Y.0+metadata", false},
{"1.2.0-x.Y.0+metadata-width-hypen", false},
{"1.2.3-rc1-with-hypen", false},
Expand All @@ -71,10 +69,15 @@ func TestNewSemver(t *testing.T) {
{"1.2.3.4-rc1-with-hypen", false},
{"1.2.3.4", false},
{"v1.2.3", false},
{"1.2.beta", true},
{"1.21.beta", true},
{"foo1.2.3", true},
{"1.7rc2", true},
{"\n1.2", true},
{"v1.7rc2", true},
{"1.0-", true},
{"", true},
{"foo", true},
}

for _, tc := range cases {
Expand Down