From 2ee7a064cae5338694cd3274328789258b4ec730 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Thu, 5 Sep 2013 18:20:25 +0200 Subject: [PATCH] Only allow specific protocols to avoid matching random stuff like fma:brotherhood. --- src/Linkification/Linkify.coffee | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Linkification/Linkify.coffee b/src/Linkification/Linkify.coffee index e81b79722..85617b39d 100644 --- a/src/Linkification/Linkify.coffee +++ b/src/Linkification/Linkify.coffee @@ -7,18 +7,25 @@ Linkify = @catchAll = /// \b ( - [a-z][\w-]+: # URL protocol and colon + ( # Allowed URL protocols and colon + https? + | ftps? + | about + | bitcoin + | git + | irc[s6]? + ): ( - /{1,3} # 1-3 slashes - | # or - [a-z0-9%] # Single letter or digit or '%' - | # or - \?(dn|x[lts]|as|kt|mt|tr)= # Magnet parameters + /{1,3} # 1-3 slashes + | # or + [a-z0-9%] # Single letter or digit or '%' ) - | # or - www\d{0,3}[.] # "www.", "www1.", "www2." … "www999." - | # or - [a-z0-9.\-]+[.][a-z]{2,4}/ # looks like domain name followed by a slash + | # or + www\d{0,3}[.] # "www.", "www1.", "www2." … "www999." + | # or + [a-z0-9.\-]+[.][a-z]{2,4}/ # looks like domain name followed by a slash + | # or + magnet:\?(dn|x[lts]|as|kt|mt|tr)= # magnet protocol with its parameters ) ( # One or more: [^\s()<>]+ # Run of non-space, non-()<>