Skip to content

Commit

Permalink
fix: trim whitespace from fetchSpec
Browse files Browse the repository at this point in the history
Fix: #35

PR-URL: #59
Credit: @isaacs
Close: #59
Reviewed-by: @wraithgar
  • Loading branch information
isaacs committed Jun 2, 2021
1 parent 00f34d7 commit d55fbfb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion npa.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function fromAlias (res, where) {

function fromRegistry (res) {
res.registry = true
const spec = res.rawSpec === '' ? 'latest' : res.rawSpec
const spec = res.rawSpec === '' ? 'latest' : res.rawSpec.trim()
// no save spec for registry components as we save based on the fetched
// version, not on the argument so this can't compute that.
res.saveSpec = null
Expand Down
40 changes: 40 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,46 @@ require('tap').test('basic', function (t) {
fetchSpec: 'latest',
raw: 'foo',
},

'foo@ 1.2 ': {
name: 'foo',
escapedName: 'foo',
type: 'range',
saveSpec: null,
fetchSpec: '1.2',
raw: 'foo@ 1.2 ',
rawSpec: ' 1.2 ',
},

'foo@ 1.2.3 ': {
name: 'foo',
escapedName: 'foo',
type: 'version',
saveSpec: null,
fetchSpec: '1.2.3',
raw: 'foo@ 1.2.3 ',
rawSpec: ' 1.2.3 ',
},

'[email protected] ': {
name: 'foo',
escapedName: 'foo',
type: 'version',
saveSpec: null,
fetchSpec: '1.2.3',
raw: '[email protected] ',
rawSpec: '1.2.3 ',
},

'foo@ 1.2.3': {
name: 'foo',
escapedName: 'foo',
type: 'version',
saveSpec: null,
fetchSpec: '1.2.3',
raw: 'foo@ 1.2.3',
rawSpec: ' 1.2.3',
},
}

Object.keys(tests).forEach(function (arg) {
Expand Down

0 comments on commit d55fbfb

Please sign in to comment.