fix: intersects() false-negative for <0.0.0-<prerelease> comparators#885
Open
gaoflow wants to merge 1 commit into
Open
fix: intersects() false-negative for <0.0.0-<prerelease> comparators#885gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
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.
Bug
intersects()returnsfalsefor two ranges that demonstrably share a version, contradictingsatisfies():0.0.0-alpha.0satisfies both ranges, so they intersect. The tell that it is specific to the0.0.0tuple:intersects('<1.0.0-rc', '>=1.0.0-alpha')is correctlytrue.Root cause
In
Comparator.intersects(classes/comparator.js), the default-mode "this comparator matches nothing" guard usesstartsWith('<0.0.0'):But the only genuinely-empty comparator values are
<0.0.0and the codebase's own null-set sentinel<0.0.0-0(seerange.js:isNullSet = c => c.value === '<0.0.0-0').<0.0.0-rc.1,<0.0.0-alpha, etc. are not empty — they match prereleases below their own id (0.0.0-0,0.0.0-alpha, ...).startsWithover-matches them and short-circuitsintersectstofalse.Fix
Only treat the two real null-set values as empty; everything else falls through to the normal opposite-direction logic. The
includePrereleasebranch above (already=== '<0.0.0-0') is untouched.Tests
test/ranges/intersects.jsgains a property-oracle block that builds a near-zero + prerelease version grid × a comparator matrix and asserts, for every pair with a real shared witness version, thatintersectsistruein both directions (1,289 witness-backed pairs). Fixture rows are added tocomparator-intersection.js(incl. the<0.0.0guards that must stayfalse) andrange-intersection.js. Full suite passes; lint clean.Relation to #884
This is independent of open #884. #884 patches set-level decomposition in
range.jsfor cases where one set pins an exact=x.y.z; it does not touchcomparator.js. Cross-applied: with #884 alone my<0.0.0-rc.1case staysfalse; with this fix alone #884's^1.2.3-alphacase staysfalse. If #884 lands first, the only overlap is the appended rows intest/fixtures/range-intersection.js(a trivial append-only rebase).