fix: use OR logic for != wildcard range expansion - #84
Open
deepakganesh78 wants to merge 1 commit into
Open
Conversation
The != wildcard expansion (e.g. !=1.0.x) was incorrectly joining its two range bounds (<1.0.0 and >=1.1.0) with AND logic, making the resulting range unsatisfiable (no version can be both <1.0.0 AND >=1.1.0). The correct semantics is OR: a version satisfies !=1.0.x if it is either <1.0.0 OR >=1.1.0 (i.e., outside the 1.0.x range). This fix splits the != wildcard expansion into separate OR parts instead of combining them in a single AND group. Fixes blang#80 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #80
Problem
The
!=wildcard expansion (e.g.!=1.0.x) was incorrectly joining its two range bounds (<1.0.0and>=1.1.0) with AND logic within the same comparator group. Since no version can satisfy both<1.0.0 AND >=1.1.0simultaneously, the resulting range was unsatisfiable — every version failed the check.Root Cause
In
expandWildcardVersion(), the!=case appended<flatVersiontonewPartsand then the incremented>=versionwas also appended tonewParts. Since all entries in a singlenewPartsslice are AND'd together during range evaluation, this produced an impossible constraint.Fix
Split the
!=wildcard expansion into separate OR parts.!=1.0.xnow correctly expands to<1.0.0 || >=1.1.0, meaning a version matches if it is outside the 1.0.x range.Reproduction
go r, _ := semver.ParseRange("!=1.0.x") v, _ := semver.Parse("1.1.1") fmt.Println(r(v)) // Before: false, After: trueValidation
go test ./...passes (root module + v4)go vet ./...cleangofmtclean