Skip to content

fix: recognize upper-bound-only subsets - #956

Open
Ultroncn wants to merge 1 commit into
npm:mainfrom
Ultroncn:fix/subset-upper-bound-only
Open

Ultroncn wants to merge 1 commit into
npm:mainfrom
Ultroncn:fix/subset-upper-bound-only

Conversation

@Ultroncn

Copy link
Copy Markdown

Hi! Thanks for maintaining node-semver. I found a small bug in subset() and would love your review.

Problem (fixes #949)

subset() returns false for ranges that only have an upper bound, even when they clearly are subsets:

subset('<2.0.0', '*')        // false, should be true
subset('<2.0.0', '>=0.0.0')  // false, should be true
subset('0.x', '*')           // false, should be true

Two causes in simpleSubset (ranges/subset.js):

  1. When sub has an upper bound but no lower bound, the code returned false unconditionally. But a missing lower bound is still bounded below by the lowest version (0.0.0, or 0.0.0-0 with includePrerelease), so sub is only excluded when a lower bound in dom rejects that minimum.
  2. 0.x expands to >=0.0.0 <1.0.0-0, and <1.0.0-0 was treated as stricter than <1.0.0 — but without includePrerelease both admit the same versions (same reasoning as the existing needDomLTPre exception for <1.2.3-0).

Fix

  • Only return false for a missing lower bound when a >/>= comparator in dom rejects the minimum version.
  • Treat <X-0 as the same upper bound as <X when not in prerelease mode (same tuple, single 0 prerelease identifier).

Tests

Added 14 cases to test/ranges/subset.js (the 5 from the issue, reverse controls that must stay false, and includePrerelease mirrors). 6 of the new tests fail on the old code and all pass with the fix. npm test passes: 54 passed, 23465 assertions, 0 failures, 100% coverage. I also ran a 4000-pair differential fuzz against a satisfies-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).

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
@Ultroncn
Ultroncn requested a review from a team as a code owner November 18, 2026 21:31
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.

[BUG] subset() returns false for an upper-bound-only range such as subset('<2.0.0', '*')

1 participant