Explain the reason for double escapes

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-05-11 22:28:14 +05:30
parent ef15968a3d
commit b521797f4d

View file

@ -1,3 +1,8 @@
/*
The regex is split into component strings;
meaning that any escapes (\) must be also
be escaped.
*/
const scheme = "(?:https|http|ftp):\\/\\/"; const scheme = "(?:https|http|ftp):\\/\\/";
const host = "[a-zA-Z0-9:.\\[\\]-]"; const host = "[a-zA-Z0-9:.\\[\\]-]";
@ -24,7 +29,6 @@ Things to keep in mind:
them in path or fragment components. them in path or fragment components.
https://matrix.org/<smiley> - valid https://matrix.org/<smiley> - valid
https://matrix.org<smiley> - invalid https://matrix.org<smiley> - invalid
2. Do not treat punctuation at the end as a part of the URL (.,?!) 2. Do not treat punctuation at the end as a part of the URL (.,?!)
*/ */
const urlRegex = `${scheme}${host}+(?:${additional}|${endASCII})`; const urlRegex = `${scheme}${host}+(?:${additional}|${endASCII})`;