mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-11 17:50:29 +03:00
sanitize string before used in regex to prevent crash (#2219)
This commit is contained in:
parent
d8d4bce287
commit
9fe67da98b
4 changed files with 13 additions and 5 deletions
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue