hashicorp / hashicorp/go-version

PreRelease comparison bug?

Open
#61 1 comment 3 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.8k
Forks
165
Avg merge
23h 42m
Merged PRs (30d)
2

Description

In looking at the ComparePreReleases test cases...

```
func TestComparePreReleases(t *testing.T) {
cases := []struct {
v1 string
v2 string
expected int
}{
...
{"5.4-alpha", "5.4-alpha.beta", 1},
}
```
I'm noticing that `5.4-alpha` is larger (has a higher precedence) than `5.4-alpha.beta`. However when reading over the precedence rules of pre-releases in semver (https://semver.org/#spec-item-11)
```
A larger set of pre-release fields has a higher precedence than a smaller set,
if all of the preceding identifiers are equal.
Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.
```

In this test case, all the preceding identifiers are equal - "5.4" - and the larger set "alpha.beta" has a lower precedence than the smaller set "alpha". Shouldn't it have a higher precedence?

Contributor guide

Open the contributing guide

Research direction

Locate the TestComparePreReleases test cases in the go-version repository and compare the result for 5.4-alpha with 5.4-alpha.beta against the SemVer 2.0.0 precedence rule linked in the issue. Confirm the intended ordering and update the comparison behavior and regression coverage so the test reflects the correct precedence.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.