Skip to content

fix: make numeric prerelease comparison antisymmetric - #331

Open
feiiiiii5 wants to merge 1 commit into
Masterminds:masterfrom
feiiiiii5:feiiiiii5/1127-D309
Open

feiiiiii5 wants to merge 1 commit into
Masterminds:masterfrom
feiiiiii5:feiiiiii5/1127-D309

Conversation

@feiiiiii5

Copy link
Copy Markdown

What

comparePrePart() returned -1 after parsing two prerelease numeric identifiers whenever si > oi was false — including when si == oi. Two distinct prerelease strings that parse to the same number therefore compared less-than in both directions: LessThan(a,b) and LessThan(b,a) were both true, Equal was false, and sort.Sort(Collection) became input-order dependent.

Reachable through the public New() constructor, which intentionally skips validation: New(1,0,0,"01","") vs New(1,0,0,"1",""). NewVersion still rejects "01" (spec-correct, unchanged).

How

Three-way comparison: si > oi → 1, si < oi → -1, otherwise 0. All other comparison branches are untouched.

Verification

  • New TestCompareNumericallyEqualIdentifiers: base-red 8 assertion failures; with fix PASS.
  • go test ./... PASS (50 top-level tests, 0 failures); go vet ./... clean; gofmt -l clean.

AI-assisted development. Human review requested before merge.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant