Fix:Crash when matching with author names ending in ??? by escaping regex strings #2265

This commit is contained in:
advplyr 2023-10-30 16:35:41 -05:00
parent 2ef11e5ad0
commit 9616d99640
2 changed files with 14 additions and 2 deletions

View file

@ -192,4 +192,16 @@ module.exports.asciiOnlyToLowerCase = (str) => {
}
}
return temp
}
/**
* Escape string used in RegExp
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
*
* @param {string} str
* @returns {string}
*/
module.exports.escapeRegExp = (str) => {
if (typeof str !== 'string') return ''
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
}