From 2ac423551f43b12b9b92b4f9709e031278eb9e9b Mon Sep 17 00:00:00 2001 From: Sam Carlton Date: Sun, 24 Apr 2022 10:57:59 -0500 Subject: [PATCH] Fix error on names with pluses --- helpers/matching.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/helpers/matching.js b/helpers/matching.js index 3894a47..6999baf 100644 --- a/helpers/matching.js +++ b/helpers/matching.js @@ -1,7 +1,13 @@ +function escapeRegex ( string ) { + return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') +} // Match whole word export function matchesWholeWord (needle, haystack) { - return new RegExp('\\b' + needle + '\\b').test(haystack) + // console.log('haystack', haystack) + // console.trace('needle', needle) + + return new RegExp('\\b' + escapeRegex( needle ) + '\\b').test(haystack) } export function fuzzyMatchesWholeWord (needle, haystack) {