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

Aperta
#949 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, node.js
Ambito
backend

Direzione di ricerca

Start in ranges/subset.js at simpleSubset, especially the lt && hasDomGT && !gt condition described in the issue. Trace how missing lower bounds and * are normalized, then check the existing subset tests for these range combinations. Done means the first five reproductions return true while existing subset behavior remains correct.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Is there an existing issue for this?
  • I have searched the existing issues
Current Behavior

subset(sub, dom) returns false when sub has only an upper bound (< or <=) and dom has a lower bound, including *, which subset treats as >=0.0.0. Every version that satisfies <2.0.0 also satisfies *, so the README's "entirely contained" definition gives true.

subset('<1.0.0', '0.x') is a related false negative: 0.x is >=0.0.0 <1.0.0-0, which admits the same non-prerelease versions as <1.0.0.

Expected Behavior

The first five lines below print true.

In ranges/subset.js, simpleSubset replaces * in dom with >=0.0.0 and then returns false for lt && hasDomGT && !gt, which treats a missing lower bound in sub as unbounded below instead of >=0.0.0.

Steps To Reproduce
const { subset } = require('semver')
console.log(subset('<2.0.0', '*'))
console.log(subset('<2', '*'))
console.log(subset('<2.0.0', '>=0.0.0'))
console.log(subset('<2.0.0', '>=0.0.0-0'))
console.log(subset('<1.0.0', '0.x'))
console.log(subset('<1.0.0', '>=0.0.0 <1.0.0'))
console.log(subset('^1.2.3', '*'))

Output:

false
false
false
false
false
true
true
Environment
  • semver: 7.8.6, also main at b37b033
  • Node: 26.13.0
  • OS: Ubuntu Linux
  • platform: x86_64

Credit: https://ucsbplse.github.io/

Lingua principale
JavaScript
Stelle
5.5k
Fork
624
Merge medio
6g 1h
PR unite (30g)
13

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di npm/node-semver

Tutte le issue di npm/node-semver

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.