diff --git a/public/src/client/search.js b/public/src/client/search.js index d12bde2193..7416e95c21 100644 --- a/public/src/client/search.js +++ b/public/src/client/search.js @@ -138,7 +138,7 @@ define('forum/search', ['search', 'autocomplete', 'storage'], function (searchMo if (!searchQuery) { return; } - + searchQuery = utils.escapeHTML(searchQuery); var regexStr = searchQuery.replace(/^"/, '').replace(/"$/, '').trim().split(' ').join('|'); var regex = new RegExp('(' + regexStr + ')', 'gi'); @@ -151,11 +151,15 @@ define('forum/search', ['search', 'autocomplete', 'storage'], function (searchMo nested.push($('
').append($(this))); }); - result.html(result.html().replace(regex, '$1')); + result.html(result.html().replace(regex, function (match, p1) { + return '' + p1 + ''; + })); - for (var i = 0, ii = nested.length; i < ii; i += 1) { - result.html(result.html().replace('', nested[i].html())); - } + nested.forEach(function (nestedEl, i) { + result.html(result.html().replace('', function () { + return nestedEl.html(); + })); + }); }); $('.search-result-text').find('img:not(.not-responsive)').addClass('img-responsive'); diff --git a/public/src/modules/search.js b/public/src/modules/search.js index f135271d50..ea0f775fd1 100644 --- a/public/src/modules/search.js +++ b/public/src/modules/search.js @@ -7,24 +7,14 @@ define('search', ['navigator', 'translator', 'storage'], function (nav, translat }; Search.query = function (data, callback) { - var term = data.term; - // Detect if a tid was specified - var topicSearch = term.match(/^in:topic-([\d]+) /); + var topicSearch = data.term.match(/^in:topic-([\d]+) /); if (!topicSearch) { - term = term.replace(/^[ ?#]*/, ''); - - try { - term = encodeURIComponent(term); - } catch (e) { - return app.alertError('[[error:invalid-search-term]]'); - } - ajaxify.go('search?' + createQueryString(data)); callback(); } else { - var cleanedTerm = term.replace(topicSearch[0], ''); + var cleanedTerm = data.term.replace(topicSearch[0], ''); var tid = topicSearch[1]; if (cleanedTerm.length > 0) { @@ -36,8 +26,15 @@ define('search', ['navigator', 'translator', 'storage'], function (nav, translat function createQueryString(data) { var searchIn = data.in || 'titlesposts'; var postedBy = data.by || ''; + var term = data.term.replace(/^[ ?#]*/, ''); + try { + term = encodeURIComponent(term); + } catch (e) { + return app.alertError('[[error:invalid-search-term]]'); + } + var query = { - term: data.term, + term: term, in: searchIn, };