sanitize string before used in regex to prevent crash (#2219)
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
/**
|
||||
* https://www.npmjs.com/package/escape-string-regexp
|
||||
*/
|
||||
export const sanitizeForRegex = (unsafeText: string): string =>
|
||||
unsafeText.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
|
||||
|
||||
export const HTTP_URL_PATTERN = `https?:\\/\\/(?:www\\.)?(?:[^\\s)]*)(?<![.,:;!/?()[\\]\\s]+)`;
|
||||
|
||||
export const URL_REG = new RegExp(HTTP_URL_PATTERN, 'g');
|
||||
|
||||
Reference in New Issue
Block a user