Repository navigation
Conversation
subset() returned false when sub had only an upper bound and dom had a lower bound, including '*', which subset treats as >=0.0.0. A missing lower bound is bounded below by the lowest version (0.0.0, or 0.0.0-0 with includePrerelease), so it only excludes sub when a lower bound in dom rejects that minimum. Also treat <X-0 as the same upper bound as <X without includePrerelease, so '<1.0.0' is a subset of '0.x'. Fixes npm#949
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.
Hi! Thanks for maintaining node-semver. I found a small bug in
subset()and would love your review.Problem (fixes #949)
subset()returnsfalsefor ranges that only have an upper bound, even when they clearly are subsets:Two causes in
simpleSubset(ranges/subset.js):falseunconditionally. But a missing lower bound is still bounded below by the lowest version (0.0.0, or 0.0.0-0 withincludePrerelease), so sub is only excluded when a lower bound in dom rejects that minimum.0.xexpands to>=0.0.0 <1.0.0-0, and<1.0.0-0was treated as stricter than<1.0.0— but withoutincludePrereleaseboth admit the same versions (same reasoning as the existingneedDomLTPreexception for<1.2.3-0).Fix
falsefor a missing lower bound when a>/>=comparator in dom rejects the minimum version.<X-0as the same upper bound as<Xwhen not in prerelease mode (same tuple, single0prerelease identifier).Tests
Added 14 cases to
test/ranges/subset.js(the 5 from the issue, reverse controls that must stayfalse, andincludePrereleasemirrors). 6 of the new tests fail on the old code and all pass with the fix.npm testpasses: 54 passed, 23465 assertions, 0 failures, 100% coverage. I also ran a 4000-pair differential fuzz against asatisfies-based brute-force check: 0 newly introduced inconsistencies (21 pre-existing ones of exactly this kind are fixed; the rest are pre-existing subset limitations outside this issue's scope).