Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[BUG] new Range(comparator).test() throws TypeError for a prerelease version

Aperta Adatta ai principianti
#908 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Inizia in classes/range.js, nel ramo Comparator (L21-27), nell’assegnazione di options (L29) e in Range.test/testSet intorno a L210/L550. Riproduci l’esempio Node fornito di semver 7.8.5, incluso satisfies(version, comparator). Il lavoro è completato quando i range costruiti con Comparator restituiscono il booleano previsto per le versioni prerelease senza generare eccezioni.

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

Descrizione

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

When a Range is constructed from a Comparator object, range.options is never set. Testing a prerelease version against that range then throws instead of returning a boolean. satisfies(version, comparator) goes through the same path and throws too.

Cause: in classes/range.js (v7.8.5), the range instanceof Comparator branch (L21-27) returns before this.options = options (L29). test() passes this.options (L210) to testSet, which reads options.includePrerelease (L550).

(Found by an AI system I use; a search of the tracker found nothing covering it.)

Expected Behavior

The same result as for the equivalent string range: true for 1.0.0-beta against >=1.0.0-alpha. Or, if a Comparator argument is not supported, a clear error at construction. The README does not document it either way.

Steps To Reproduce
  1. npm i [email protected]
  2. Run:
    const semver = require('semver')
    const r = new semver.Range(new semver.Comparator('>=1.0.0-alpha'))
    console.log(new semver.Range('>=1.0.0-alpha').test('1.0.0-beta'))  // true
    console.log(r.options)                                            // undefined
    console.log(r.test('1.0.0-beta'))
    
  3. See error:
    TypeError: Cannot read properties of undefined (reading 'includePrerelease')
        at testSet (.../semver/classes/range.js:550:45)
        at Range.test (.../semver/classes/range.js:210:11)
    

Same on 7.7.3, where the lines are range.js:530 and :207.

Environment
  • npm: n/a (library called directly from node)
  • Node: v24.12.0
  • OS: Windows 11 Pro
  • platform: x64 desktop
  • semver: 7.8.5 (latest) and 7.7.3
Lingua principale
JavaScript
Stelle
5.5k
Fork
607
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

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.