Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/utils/format-search-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class TextOutputStream extends Minipass {
description: strip(data.description ?? ''),
keywords: [],
name: strip(data.name),
version: data.version,
version: strip(data.version ?? ''),
}
if (Array.isArray(data.keywords)) {
pkg.keywords = data.keywords.map(strip)
Expand Down
28 changes: 28 additions & 0 deletions test/lib/commands/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,34 @@ t.test('search', t => {
t.matchSnapshot(joinedOutput(), 'should have filtered expected search results')
})

t.test('strips control characters from version', async t => {
const { npm, joinedOutput } = await loadMockNpm(t)
const registry = new MockRegistry({
tap: t,
registry: npm.config.get('registry'),
})

const esc = String.fromCharCode(27)
registry.search({ results: [{
name: 'foo',
scope: 'unscoped',
version: `1.0.0${esc}[31mnot-really`,
description: '',
keywords: [],
date: null,
author: { name: 'Foo', email: 'foo@npmjs.com' },
publisher: { username: 'foo', email: 'foo@npmjs.com' },
maintainers: [
{ username: 'foo', email: 'foo@npmjs.com' },
],
}] })

await npm.exec('search', ['foo'])

t.notMatch(joinedOutput(), esc, 'no escape sequence reaches the terminal')
t.match(joinedOutput(), '1.0.0not-really', 'version text is preserved')
})

t.test('empty search results', async t => {
const { npm, joinedOutput } = await loadMockNpm(t)
const registry = new MockRegistry({
Expand Down
Loading