Skip to content
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

Fixing issue where validation of constraint section gave false positives #186

Merged
merged 1 commit into from Aug 15, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion constraints.go
Expand Up @@ -180,8 +180,13 @@ func init() {
ops,
cvRegex))

// The first time a constraint shows up will look slightly different from
// future times it shows up due to a leading space or comma in a given
// string.
validConstraintRegex = regexp.MustCompile(fmt.Sprintf(
`^(\s*(%s)\s*(%s)\s*\,?)+$`,
`^(\s*(%s)\s*(%s)\s*)((?:\s+|,\s*)(%s)\s*(%s)\s*)*$`,
ops,
cvRegex,
ops,
cvRegex))
}
Expand Down
9 changes: 9 additions & 0 deletions constraints_test.go
Expand Up @@ -231,6 +231,15 @@ func TestNewConstraint(t *testing.T) {

// The 3 - 4 should be broken into 2 by the range rewriting
{"3 - 4 || => 3.0, < 4", 2, 2, false},

// Due to having 4 parts these should produce an error. See
// https://github.com/Masterminds/semver/issues/185 for the reason for
// these tests.
{"12.3.4.1234", 0, 0, true},
{"12.23.4.1234", 0, 0, true},
{"12.3.34.1234", 0, 0, true},
{"12.3.34 ~1.2.3", 1, 2, false},
{"12.3.34~ 1.2.3", 0, 0, true},
}

for _, tc := range tests {
Expand Down
7 changes: 7 additions & 0 deletions version_test.go
Expand Up @@ -87,6 +87,13 @@ func TestNewVersion(t *testing.T) {
{"1.2.2147483648", false},
{"1.2147483648.3", false},
{"2147483648.3.0", false},

// Due to having 4 parts these should produce an error. See
// https://github.com/Masterminds/semver/issues/185 for the reason for
// these tests.
{"12.3.4.1234", true},
{"12.23.4.1234", true},
{"12.3.34.1234", true},
}

for _, tc := range tests {
Expand Down