Repository navigation
Do not compact a dev-free constraint into bare != constraints that match dev - #189
Merged
Merged
Conversation
The < N || > N to != N swap in compactConstraint changes dev-branch matching: a bare != N matches every dev-* version, while < N || > N matches none. So "> 1.0.0 != 2.0.0 || < 1.9.0" (matches no branch) compacted to "!= 2.0.0" (matches every branch), and Semver::satisfies flipped after compaction. Skip the swap when it would produce a bare != for a constraint whose branches do not already include all dev versions; a bounded conjunctive != (e.g. [!= 3 < 5]) still keeps a numeric bound and is unaffected.
The previous check only handled two numeric intervals, so e.g. "> 1.0.0 != 2.0.0 != 3.0.0 || < 1.5" still compacted to "!= 2.0 != 3.0", which matches every dev-* version. Decide once before the loop whether the numeric part is the whole line minus single points, and skip the != swap entirely in that case unless the branches already match all dev versions. This also takes the check out of the per-interval hot path.
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.
Supersedes #184 and keeps @dngr2's original commit as the base.
Intervals::compactConstraint()turns[.., <N] || [>N, ..]into!= N. A bare!= Nmatches everydev-*version, but< N || > Nmatches none. So a constraint that matches no dev branch could be compacted into one that matches all of them, e.g.> 1.0.0 != 2.0.0 || < 1.9.0became!= 2.0.0.#184 fixed this for two intervals. The follow-up commit handles the general case:
2 === $count, so with two or more excluded points (> 1.0.0 != 2.0.0 != 3.0.0 || < 1.5, with or without|| dev-bar) the result was still[!= 2.0 != 3.0], which matches all dev. The check now runs once before the loop. It asks whether the numeric part is the whole line minus single points, and if so skips the!=swap unless the branches already match all dev (exclude === true).!= 2 < 3still compact as before because they keep a numeric bound.compactProviderentries with exact expected output, plus a data-driven test that checks the compacted constraint is equivalent to the original (isSubsetOfboth ways) and has the same dev matching. Several of these fail with the Do not compact a dev-free constraint into a bare != that matches dev #184 fix alone.Closes #184