Chat: Don't allow unmatched square brackets in hyperlinks (#10681)

This commit is contained in:
Alex "Mathy 2024-11-18 16:17:58 -06:00 committed by GitHub
parent e8e6ac218e
commit 7a8ebe8155
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -39,7 +39,9 @@ REGEXFREE SOURCE FOR LINKREGEX
|
# parentheses in URLs should be matched, so they're not confused
# for parentheses around URLs
\( ( [^\\s()<>&] | &amp; )* \)
\( ( [^\s()<>&[\]] | &amp; )* \)
|
\[ ( [^\s()<>&[\]] | &amp; )* ]
)*
# URLs usually don't end with punctuation, so don't allow
# punctuation symbols that probably arent related to URL.
@ -47,7 +49,7 @@ REGEXFREE SOURCE FOR LINKREGEX
[^\s()[\]{}\".,!?;:&<>*`^~\\]
|
# annoyingly, Wikipedia URLs often end in )
\( ( [^\s()<>&] | &amp; )* \)
\( ( [^\s()<>&[\]] | &amp; )* \)
)
)?
)?
@ -58,7 +60,7 @@ REGEXFREE SOURCE FOR LINKREGEX
(?! [^ ]*&gt; )
*/
export const linkRegex = /(?:(?:https?:\/\/[a-z0-9-]+(?:\.[a-z0-9-]+)*|www\.[a-z0-9-]+(?:\.[a-z0-9-]+)+|\b[a-z0-9-]+(?:\.[a-z0-9-]+)*\.(?:(?:com?|org|net|edu|info|us|jp)\b|[a-z]{2,3}(?=:[0-9]|\/)))(?::[0-9]+)?(?:\/(?:(?:[^\s()&<>]|&amp;|&quot;|\((?:[^\\s()<>&]|&amp;)*\))*(?:[^\s()[\]{}".,!?;:&<>*`^~\\]|\((?:[^\s()<>&]|&amp;)*\)))?)?|[a-z0-9.]+@[a-z0-9-]+(?:\.[a-z0-9-]+)*\.[a-z]{2,})(?![^ ]*&gt;)/ig;
export const linkRegex = /(?:(?:https?:\/\/[a-z0-9-]+(?:\.[a-z0-9-]+)*|www\.[a-z0-9-]+(?:\.[a-z0-9-]+)+|\b[a-z0-9-]+(?:\.[a-z0-9-]+)*\.(?:(?:com?|org|net|edu|info|us|jp)\b|[a-z]{2,3}(?=:[0-9]|\/)))(?::[0-9]+)?(?:\/(?:(?:[^\s()&<>]|&amp;|&quot;|\((?:[^\s()<>&[\]]|&amp;)*\)|\[(?:[^\s()<>&[\]]|&amp;)*])*(?:[^\s()[\]{}".,!?;:&<>*`^~\\]|\((?:[^\s()<>&[\]]|&amp;)*\)))?)?|[a-z0-9.]+@[a-z0-9-]+(?:\.[a-z0-9-]+)*\.[a-z]{2,})(?![^ ]*&gt;)/ig;
/**
* A span is a part of the text that's formatted. In the text: