Fix to check if searchTerm is not "undefined" before trying to use it to filter search results.

Signed-off-by: Florent Viard <fviard@lacie.com>
pull/1882/head
Florent Viard 2013-09-10 17:46:10 +00:00
parent c4fcedbb8d
commit 6f478c4de1
1 changed files with 4 additions and 2 deletions

View File

@ -79,10 +79,12 @@ exports.search = function(searchTerm, maxCacheAge, cb) {
exports.getAvailablePlugins(maxCacheAge, function(er, results) { exports.getAvailablePlugins(maxCacheAge, function(er, results) {
if(er) return cb && cb(er); if(er) return cb && cb(er);
var res = {}; var res = {};
searchTerm = searchTerm.toLowerCase(); if (searchTerm)
searchTerm = searchTerm.toLowerCase();
for (var pluginName in results) { // for every available plugin for (var pluginName in results) { // for every available plugin
if (pluginName.indexOf(plugins.prefix) != 0) continue; // TODO: Also search in keywords here! if (pluginName.indexOf(plugins.prefix) != 0) continue; // TODO: Also search in keywords here!
if(pluginName.indexOf(searchTerm) < 0 && results[pluginName].description.indexOf(searchTerm) < 0) continue;
if(searchTerm && pluginName.indexOf(searchTerm) < 0 && results[pluginName].description.indexOf(searchTerm) < 0) continue;
res[pluginName] = results[pluginName]; res[pluginName] = results[pluginName];
} }
cb && cb(null, res) cb && cb(null, res)