Skip to content

Commit

Permalink
fix: escape regexp characters
Browse files Browse the repository at this point in the history
  • Loading branch information
troggy committed Oct 8, 2016
1 parent f6b6a8e commit 71c345b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/leo-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@
window.postMessage({ type: 'LeoExportExtension.AddDropdownHideHandler' }, '*');
};

escapeRegExp = function(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
};

highlightWord = function(word, string) {
var re = new RegExp("\\b" + word + "\\b", "ig");
var re = new RegExp("\\b" + escapeRegExp(word) + "\\b", "ig");
return string.replace(re, '<b>$&</b>');
};

Expand Down

0 comments on commit 71c345b

Please sign in to comment.