Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Commit b271ed2

Browse files
SimenBiarna
authored andcommitted
search: Exit early if no arguments provided to search
Fixes: #11983 PR-URL: #11984 Credit: @SimenB Reviewed-By: @iarna
1 parent 3e41360 commit b271ed2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/search.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ function search (args, silent, staleness, cb) {
4949
return s.toLowerCase()
5050
}).filter(function (s) { return s })
5151

52+
if (opts.length === 0) {
53+
return cb(new Error('search must be called with arguments'))
54+
}
55+
5256
if (typeof searchexclude === 'string') {
5357
searchexclude = searchexclude.split(/\s+/)
5458
} else {

test/tap/search.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ test('No previous cache, init cache triggered by first search', function (t) {
7474
})
7575
})
7676

77+
test('no arguments provided should error', function (t) {
78+
common.npm(['search'], [], function (err, code, stdout, stderr) {
79+
if (err) throw err
80+
t.equal(code, 1, 'search finished unsuccessfully')
81+
82+
t.match(
83+
stderr,
84+
/search must be called with arguments/,
85+
'should have correct error message'
86+
)
87+
t.end()
88+
})
89+
})
90+
7791
test('previous cache, _updated set, should trigger since request', function (t) {
7892
setupCache()
7993

0 commit comments

Comments
 (0)