Skip to content

Commit 36439e4

Browse files
author
i529015
committed
using re[t.BUILD] in parseComparator
1 parent 4299208 commit 36439e4

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

classes/range.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Range {
3333
// First reduce all whitespace as much as possible so we do not have to rely
3434
// on potentially slow regexes like \s*. This is then stored and used for
3535
// future error messages as well.
36-
this.raw = range.trim().replace(SPACE_CHARACTERS, ' ').replace(/\+[^ ]*/g, '')
36+
this.raw = range.trim().replace(SPACE_CHARACTERS, ' ')
3737

3838
// First, split on ||
3939
this.set = this.raw
@@ -255,6 +255,7 @@ const isSatisfiable = (comparators, options) => {
255255
// already replaced the hyphen ranges
256256
// turn into a set of JUST comparators.
257257
const parseComparator = (comp, options) => {
258+
comp = comp.replace(re[t.BUILD], '')
258259
debug('comp', comp, options)
259260
comp = replaceCarets(comp, options)
260261
debug('caret', comp)
@@ -399,11 +400,6 @@ const replaceXRange = (comp, options) => {
399400
const xp = xm || isX(p)
400401
const anyX = xp
401402

402-
// Disallow prerelease with any X-range or partial version
403-
if ((xM || xm || xp) && pr) {
404-
throw new TypeError('Prerelease not allowed with X-ranges or partial versions')
405-
}
406-
407403
if (gtlt === '=' && anyX) {
408404
gtlt = ''
409405
}

test/classes/range.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -129,50 +129,46 @@ test('cache', (t) => {
129129

130130
test('Build metadata is allowed and ignored for X-ranges and partials', t => {
131131
const buildCases = [
132-
'1.x.x+build >2.x.x+build',
133-
'>=1.x.x+build <2.x.x+build',
132+
'1.x.x+build >2.x+build',
133+
'>=1.x+build <2.x.x+build',
134134
'1.x.x+build || 2.x.x+build',
135-
'1.x.x+build.123',
135+
'1.x+build.123',
136136
'1.x.x+meta-data',
137137
'1.x.x+build.123 >2.x.x+meta-data',
138138
'1.x.x+build <2.x.x+meta',
139-
'>1.x.x+build <=2.x.x+meta',
139+
'>1.x+build <=2.x.x+meta',
140140
' 1.x.x+build >2.x.x+build ',
141+
'^1.x+build',
142+
'^1.x.x+build',
143+
'^1.2.x+build',
144+
'^1.x+meta-data',
145+
'^1.x.x+build.123',
146+
'~1.x+build',
147+
'~1.x.x+build',
148+
'~1.2.x+build',
149+
'~1.x+meta-data',
150+
'~1.x.x+build.123',
151+
'^1.x.x+build || ~2.x.x+meta',
152+
'~1.x.x+build >2.x+meta',
153+
'^1.x+build.123 <2.x.x+meta-data',
141154
]
142155
t.plan(buildCases.length)
143156
buildCases.forEach(range => {
144157
t.doesNotThrow(() => new Range(range), `${range} should not throw`)
145158
})
159+
t.end()
146160
})
147161

148-
test('Build metadata with prerelease in X-ranges/partials throws', t => {
162+
test('Build metadata with prerelease in X-ranges/partials', t => {
149163
const cases = [
150164
'1.x.x-alpha+build',
151-
'1.x-alpha+build',
152-
'1-alpha+build',
153165
'>1.x.x-alpha+build',
154166
'>=1.x.x-alpha+build <2.x.x+build',
155167
'1.x.x-alpha+build || 2.x.x+build',
156168
]
157169
t.plan(cases.length)
158170
cases.forEach(range => {
159-
t.throws(() => new Range(range), TypeError, `${range} should throw TypeError`)
160-
})
161-
})
162-
163-
test('Prerelease is NOT allowed with X-ranges or partials', t => {
164-
const prereleaseCases = [
165-
'1.x-alpha',
166-
'1-alpha',
167-
'1.x.x-alpha',
168-
'>1.x-alpha',
169-
'>1-alpha',
170-
'>1.x.x-alpha',
171-
'1.x.x-alpha <2.x.x-alpha',
172-
'>1.x.x-alpha <=2.x-alpha',
173-
]
174-
t.plan(prereleaseCases.length)
175-
prereleaseCases.forEach(range => {
176-
t.throws(() => new Range(range), TypeError, `${range} should throw TypeError`)
171+
t.doesNotThrow(() => new Range(range), TypeError, `${range} should not throw`)
177172
})
173+
t.end()
178174
})

0 commit comments

Comments
 (0)