diff --git a/zephyr/static/js/narrow.js b/zephyr/static/js/narrow.js index 7282be4225..4d21db2dce 100644 --- a/zephyr/static/js/narrow.js +++ b/zephyr/static/js/narrow.js @@ -296,7 +296,11 @@ exports.set_compose_defaults = function (opts) { exports.parse = function (str) { var operators = []; var search_term = []; - $.each(str.match(/"[^"]+"|\S+/g), function (idx, token) { + var matches = str.match(/"[^"]+"|\S+/g); + if (matches === null) { + return operators; + } + $.each(matches, function (idx, token) { var parts, operator; if (token.length === 0) return; diff --git a/zephyr/static/js/search.js b/zephyr/static/js/search.js index 5055001506..ead5435b60 100644 --- a/zephyr/static/js/search.js +++ b/zephyr/static/js/search.js @@ -203,12 +203,16 @@ exports.initialize = function () { // Add an entry for narrow by operators. var operators = narrow.parse(query); - var obj = {action: 'operators', query: query, operators: operators}; - var label = render_object(obj); - mapped[label] = obj; - labels.unshift(label); + if (operators.length !== 0) { + var obj = {action: 'operators', query: query, operators: operators}; + var label = render_object(obj); + mapped[label] = obj; + labels.unshift(label); - return labels; + return labels; + } else { + return []; + } }, items: 20, highlighter: function (item) { @@ -283,7 +287,7 @@ exports.initialize = function () { // operators. (The reason the other actions don't call // this codepath is that they first all blur the box to // indicate that they've done what they need to do) - if (search_query_box.val()) { + if (search_query_box.val().trim()) { narrow.activate(narrow.parse(search_query_box.val())); } search_query_box.blur();