Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(view): filter out invalid semver #7197

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading