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

Bug: Constraints::Check(...) function mistakenly returns false, expected true #46

Open
Codehardt opened this issue Feb 4, 2019 · 5 comments

Comments

@Codehardt
Copy link

Hey,

the following example shows an unexpected behavior of the constraints' check function:

v1 := MustVersion("1.7.3")
v2 := MustVersion("1.7.4~pre.0")
v3 := MustVersion("1.7.4")
if !v1.LessThan(v2) {
	panic("v1 not less than v2")
}
if !v2.LessThan(v3) {
	panic("v2 not less than v3")
}
if !v1.LessThan(v3) {
	panic("v1 not less than v3")
}
c := MustConstraint(">= 1.7.3")
if !c.Check(v1) {
	panic("constraint failed for v1")
}
if !c.Check(v3) {
	panic("constraint failed for v3")
}
if !c.Check(v2) {
	panic("constraint failed for v2")
}

My output is constraint failed for v2. The above code shows, that 1.7.3 is less than 1.7.4~pre.0 but 1.7.4~pre.0 does not match constraint >= 1.7.3.

Tested commit: v1.1.0 d40cf49b3a77bba84a7afdbd7f1dc295d114efb1

Thanks,
Marcel Gebhardt

@mitchellh
Copy link
Contributor

Hm, what is the expected behavior here with “~”. We only implement “-“ as a separator internal since that is what the SemVer spec defines clearly. I’m not familiar with how software might version using the tilde separator, perhaps we just consider it equal in behavior to “-“ which would yield the correct behavior in your report?

@Codehardt
Copy link
Author

"~" can have multiple meanings, e.g. for pre-released debian packages:

One common use of ~ is for upstream pre-releases. For example, 1.0~beta1~svn1245 sorts earlier than 1.0~beta1, which sorts earlier than 1.0

(Debian Policy Manual)

@mitchellh
Copy link
Contributor

mitchellh commented Feb 4, 2019

Hm, yeah that’s kind of awkward to special case in there. I would want to gather a few more examples of this in use before using it. For now, if you string replace “~” with “-“ you will probably get the right behavior. There are definitely edge cases and I don’t mean for that to be your solution, but I wouldn’t be comfortable jamming in any special handling for “~” until there was a wider survey done to see if that’s (1) common enough and (2) the consensus for what it means.

@Codehardt
Copy link
Author

For now, if you string replace “~” with “-“ you will probably get the right behavior

I tried replacing ~ with - but I still have the same problem:

v1 := MustVersion("1.7.3")
v2 := MustVersion("1.7.4-pre.0")
v3 := MustVersion("1.7.4")
if !v1.LessThan(v2) {
	panic("v1 not less than v2")
}
if !v2.LessThan(v3) {
	panic("v2 not less than v3")
}
if !v1.LessThan(v3) {
	panic("v1 not less than v3")
}
c := MustConstraint(">= 1.7.3")
if !c.Check(v1) {
	panic("constraint failed for v1")
}
if !c.Check(v3) {
	panic("constraint failed for v3")
}
if !c.Check(v2) {
	panic("constraint failed for v2")
}

Output: constraint failed for v2

Hmm .. 1.7.4-pre.0 is < 1.7.4 and > 1.7.3 but does not match constraint >= 1.7.3 🤔

@anupvbw
Copy link

anupvbw commented Sep 1, 2022

I have the same issue as @Codehardt. Is there a plan to fix this issue? We're currently using version 1.2.0 of go-version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants