Skip to content

Commit

Permalink
fix(view): filter out invalid semver (#7197)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored Feb 3, 2024
1 parent b0a3ba0 commit d04111d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/commands/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,13 @@ class View extends BaseCommand {

const data = []
const versions = pckmnt.versions || {}
pckmnt.versions = Object.keys(versions).sort(semver.compareLoose)
pckmnt.versions = Object.keys(versions).filter(v => {
if (semver.valid(v)) {
return true
}
log.info('view', `Ignoring invalid version: ${v}`)
return false
}).sort(semver.compareLoose)

// remove readme unless we asked for it
if (args.indexOf('readme') === -1) {
Expand Down
4 changes: 4 additions & 0 deletions tap-snapshots/test/lib/commands/view.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ dist-tags:
latest: 1.0.0
`

exports[`test/lib/commands/view.js TAP package with invalid version > must match snapshot 1`] = `
[ '1.0.0', '1.0.1' ]
`

exports[`test/lib/commands/view.js TAP package with maintainers info as object > must match snapshot 1`] = `
pink@1.0.0 | Proprietary | deps: none | versions: 2
Expand Down
8 changes: 8 additions & 0 deletions test/lib/commands/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ const packument = (nv, opts) => {
},
},
'1.0.1': {},
'100000000000000000.0.0': {
},
},
},
}
Expand Down Expand Up @@ -315,6 +317,12 @@ t.test('package with homepage', async t => {
t.matchSnapshot(outputs.join('\n'))
})

t.test('package with invalid version', async t => {
const { view, outputs } = await loadMockNpm(t, { config: { unicode: false } })
await view.exec(['orange', 'versions'])
t.matchSnapshot(outputs.join('\n'))
})

t.test('package with no versions', async t => {
const { view, outputs } = await loadMockNpm(t, { config: { unicode: false } })
await view.exec(['brown'])
Expand Down

0 comments on commit d04111d

Please sign in to comment.