From a01761e72908239bfb2aaef560ed72c14240ba0e Mon Sep 17 00:00:00 2001 From: mrfry <mr.fry@tutanota.com> Date: Wed, 12 May 2021 09:48:59 +0200 Subject: [PATCH] Regexp highlight / serach fix --- src/components/Question.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/Question.js b/src/components/Question.js index 69ea0d2..511caca 100644 --- a/src/components/Question.js +++ b/src/components/Question.js @@ -4,8 +4,12 @@ function highlightText(text, toHighlight) { if (!text) { return '' } - const re = new RegExp(toHighlight, 'gi') - return text.replace(re, `<mark>${toHighlight}</mark>`) + try { + const re = new RegExp(toHighlight, 'gi') + return text.replace(re, `<mark>${toHighlight}</mark>`) + } catch (e) { + return text + } } export default function Question({ question, searchTerm }) {