From 1deeaaeb39b898b447e5ccd46a0ccf121dbacc15 Mon Sep 17 00:00:00 2001
From: Peter Jaszkowiak
Date: Thu, 6 Apr 2017 15:20:07 -0600
Subject: [PATCH] Fix #5563
---
public/src/admin/modules/search.js | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/public/src/admin/modules/search.js b/public/src/admin/modules/search.js
index c52008fdab..7694b21b3a 100644
--- a/public/src/admin/modules/search.js
+++ b/public/src/admin/modules/search.js
@@ -1,6 +1,5 @@
'use strict';
-
define('admin/modules/search', ['mousetrap'], function (mousetrap) {
var search = {};
@@ -11,16 +10,17 @@ define('admin/modules/search', ['mousetrap'], function (mousetrap) {
var namespace = params.namespace;
var translations = params.translations;
var title = params.title;
+ var escaped = utils.escapeRegexChars(term);
var results = translations
// remove all lines without a match
- .replace(new RegExp('^(?:(?!' + term + ').)*$', 'gmi'), '')
+ .replace(new RegExp('^(?:(?!' + escaped + ').)*$', 'gmi'), '')
// remove lines that only match the title
.replace(new RegExp('(^|\\n).*?' + title + '.*?(\\n|$)', 'g'), '')
// get up to 25 characters of context on both sides of the match
// and wrap the match in a `.search-match` element
.replace(
- new RegExp('^[\\s\\S]*?(.{0,25})(' + term + ')(.{0,25})[\\s\\S]*?$', 'gmi'),
+ new RegExp('^[\\s\\S]*?(.{0,25})(' + escaped + ')(.{0,25})[\\s\\S]*?$', 'gmi'),
'...$1$2$3...
'
)
// collapse whitespace
@@ -28,7 +28,7 @@ define('admin/modules/search', ['mousetrap'], function (mousetrap) {
.trim();
title = title.replace(
- new RegExp('(^.*?)(' + term + ')(.*?$)', 'gi'),
+ new RegExp('(^.*?)(' + escaped + ')(.*?$)', 'gi'),
'$1$2$3'
);
@@ -123,7 +123,7 @@ define('admin/modules/search', ['mousetrap'], function (mousetrap) {
menu.children('.result').remove();
- var len = value.length;
+ var len = /\W/.test(value) ? 3 : value.length;
var results;
menu.toggleClass('state-start-typing', len === 0);