[BUG] range.bnf incomplete regarding whitespace and "spermies"

Abierto
#392 7 comentarios 4 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@vibhor-aggr ya está trabajando en esto.

Desde el 7/8/2026.

  • #895 de @vibhor-aggr — abierto

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
javascript
Área
tooling

Línea de trabajo

Compare range.bnf with the parser behavior covered by test/fixtures/range-parse.js, using the linked reproduction cases as the starting point. Review the documented range grammar and determine whether the intended resolution is to change the grammar, restrict parsing, or document the broader accepted syntax; done means the chosen behavior is specified and covered consistently.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Bug

What / Why

There are some discrepancies between what ranges are valid according to the BNF definition and the implementation.
As far as I'm aware, this implementation (or the BNF) is the "canonical" definition for NPM version ranges.

Every range abiding by the BNF is valid according to the implementation, but the implementation also accepts ranges as valid that are not in the BNF.

Where

How

Current Behavior

Implementation allows for whitespace within a "simple" range expression at the start of a "partial", but this does not abide by the BNF grammar.

Steps to Reproduce

Using latest release:

const semver = require('semver')

console.log(semver.validRange('>= 1.2.3 < 1.6.0', {loose: false} )) // >=1.2.3 <1.6.0
console.log(semver.validRange('^ 1.2.3 || ^ 2.4.6', {loose: false})) // >=1.2.3 <1.6.0

And tests involving
https://github.com/npm/node-semver/blob/e79ac3a450e8bb504e78b8159e3efc70895699b8/test/fixtures/range-parse.js#L28-L34
and
https://github.com/npm/node-semver/blob/e79ac3a450e8bb504e78b8159e3efc70895699b8/test/fixtures/range-parse.js#L57-L60
pass, but are not valid according to the BNF.

In particular, there is no whitespace defined between comparison operators and the number:
https://github.com/npm/node-semver/blob/e79ac3a450e8bb504e78b8159e3efc70895699b8/range.bnf#L6-L9
and the tilde definition does not allow for >:
https://github.com/npm/node-semver/blob/e79ac3a450e8bb504e78b8159e3efc70895699b8/range.bnf#L10

Expected Behavior

Either:

  1. The BNF definition is expanded to allow whitespace between

  2. The implementation is restricted to match the BNF (e.g. only accept the ranges as valid when "loose"?)

    (this obviously has backwards compatibility issues)

  3. Document clearly that the implementation can parse and accept ranges outside of those defined in the BNF. (Though, perhaps will only ever return canonical ranges that comply with the BNF?)

If updating the grammar, the following change to be sufficient:

partial    ::= ( ' ' )* xr ( '.' xr ( '.' xr qualifier ? )? )?
...
tilde      ::= '~' ('>')? partial

Though the range definition could probably also be updated to reflect how multiple spaces are allowed:

range      ::= hyphen | simple ( ( ' ' )+ simple ) * | ''
Lenguaje dominante
JavaScript
Estrellas
5.5k
Forks
624
Merge medio
6 d 1 h
PR fusionados (30 d)
13

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de npm/node-semver

Todos los issues de npm/node-semver

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.