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

オープン
#392 コメント 7 件 リアクション 4 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@vibhor-aggr がすでに取り組んでいます。

2026年8月7日 から。

  • #895 @vibhor-aggr による — オープン

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
javascript
領域
tooling

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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 ) * | ''
主要言語
JavaScript
スター
5.5k
フォーク
624
平均マージ
6日 1時間
マージ済み PR(30日)
13

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

npm/node-semver のほかの issue

npm/node-semver の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。