diff --git a/src/core/utils.js b/src/core/utils.js index f762a6a..8703a26 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -298,6 +298,15 @@ export function setBrightness(hex, dark: boolean = false) { return `#${r.toString(16)}${g.toString(16)}${b.toString(16)}`; } +/* + * escape string for use in regexp + * @param string input string + * @return escaped string + */ +function escapeRegExp(string) { + return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string +} + /* * create RegExp to search for ping in chat messages * @param name name @@ -305,5 +314,5 @@ export function setBrightness(hex, dark: boolean = false) { */ export function createNameRegExp(name: string) { if (!name) return null; - return new RegExp(`(^|\\s+)(@${name})(\\s+|$)`, 'g'); + return new RegExp(`(^|\\s+)(@${escapeRegExp(name)})(\\s+|$)`, 'g'); } diff --git a/src/utils/cellsEquals.js b/src/utils/cellsEquals.js deleted file mode 100644 index 0db28de..0000000 --- a/src/utils/cellsEquals.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - * @flow - */ - - -/** - * http://stackoverflow.com/questions/3115982/how-to-check-if-two-arrays-are-equal-with-javascript - * @param a - * @param b - * @returns {boolean} - */ -function cellsEquals(a: Cell, b: Cell): boolean { - if (a === b) return true; - if (a === null || b === null) return false; - - return (a[0] === b[0]) && (a[1] === b[1]); -} - -export default cellsEquals;