Skip to content

Commit 97a7d0a

Browse files
committed
fix(picker): spaces in wanted prevented match
1 parent 454d808 commit 97a7d0a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const semver = require('semver')
66
module.exports = pickManifest
77
function pickManifest (packument, wanted, opts) {
88
opts = opts || {}
9+
wanted = wanted.trim()
910
const spec = npa.resolve(packument.name, wanted)
1011
const type = spec.type
1112
const distTags = packument['dist-tags'] || {}

test/index.js

+14
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,17 @@ test('errors if metadata has no versions', t => {
192192
}, {code: 'ENOVERSIONS'})
193193
t.done()
194194
})
195+
196+
test('matches even if requested version has spaces', t => {
197+
const metadata = {
198+
versions: {
199+
'1.0.0': { version: '1.0.0' },
200+
'1.0.1': { version: '1.0.1' },
201+
'1.0.2': { version: '1.0.2' },
202+
'2.0.0': { version: '2.0.0' }
203+
}
204+
}
205+
const manifest = pickManifest(metadata, ' 1.0.0 ')
206+
t.equal(manifest.version, '1.0.0', 'picked the right manifest even though `wanted` had spaced')
207+
t.done()
208+
})

0 commit comments

Comments
 (0)