diff --git a/classes/range.js b/classes/range.js index 1efaaf2c..766d505a 100644 --- a/classes/range.js +++ b/classes/range.js @@ -277,6 +277,11 @@ const parseComparator = (comp, options) => { const isX = id => !id || id.toLowerCase() === 'x' || id === '*' +const invalidXRangeOrder = (M, m, p) => ( + (isX(M) && !isX(m)) || + (isX(m) && p && !isX(p)) +) + // ~, ~> --> * (any, kinda silly) // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0 // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0 @@ -402,6 +407,10 @@ const replaceXRange = (comp, options) => { const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE] return comp.replace(r, (ret, gtlt, M, m, p, pr) => { debug('xRange', comp, ret, gtlt, M, m, p, pr) + if (invalidXRangeOrder(M, m, p)) { + return comp + } + const xM = isX(M) const xm = xM || isX(m) const xp = xm || isX(p) diff --git a/test/fixtures/range-parse.js b/test/fixtures/range-parse.js index 8c8f41c7..c99ca40a 100644 --- a/test/fixtures/range-parse.js +++ b/test/fixtures/range-parse.js @@ -38,6 +38,12 @@ module.exports = [ ['2.x.x', '>=2.0.0 <3.0.0-0'], ['1.2.x', '>=1.2.0 <1.3.0-0'], ['1.2.x || 2.x', '>=1.2.0 <1.3.0-0||>=2.0.0 <3.0.0-0'], + ['1.x.5', null], + ['1.*.5', null], + ['1.x.5 || 2.x', null], + ['x.1', null], + ['x.1.2', null], + ['x.x.1', null], ['x', '*'], ['2.*.*', '>=2.0.0 <3.0.0-0'], ['1.2.*', '>=1.2.0 <1.3.0-0'],