From 6b8b68d4ef900032bd63736c1a2565621cdafd0c Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Fri, 23 Jan 2015 19:03:15 +0100 Subject: [PATCH] Auto-link URLs without closing parenthesis at end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently Pokémon Showdown doesn't auto-link URLs properly in the following form. (Check out http://play.pokemonshowdown.com/) In this case, it's obvious that `)` not part of an URL, but the current auto-linker believes that it is. Making `)` illegal character at end of URL doesn't solve the problem, as sometimes URLs actually do contain parenthesis. The new URL regex supports one level of parenthesis (regexes don't support recursion, but if you have more than one layer of parenthesis in an URL, you are doing something wrong). This is a case with URLs on Wikipedia. https://en.wikipedia.org/wiki/Pokémon_(disambiguation) --- js/battledata.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/battledata.js b/js/battledata.js index 43d505adc..7576e8c28 100644 --- a/js/battledata.js +++ b/js/battledata.js @@ -330,7 +330,7 @@ var Tools = { options.hidestrikethrough ? '$1' : '$1'); // linking of URIs if (!options.hidelinks) { - str = str.replace(/https?\:\/\/[a-z0-9-.]+(?:\:[0-9]+)?(?:\/(?:[^\s]*[^\s?.,])?)?|[a-z0-9.]+\@[a-z0-9.]+\.[a-z0-9]{2,3}|(?:[a-z0-9](?:[a-z0-9-\.]*[a-z0-9])?\.(?:com|org|net|edu|us|jp)(?:\:[0-9]+)?|qmark\.tk)(?:(?:\/(?:[^\s]*[^\s?.,])?)?)\b/ig, function(uri) { + str = str.replace(/https?\:\/\/[a-z0-9-.]+(?:\:[0-9]+)?(?:\/(?:\([^\s()]*\)|[^\s?.,()])*)?|[a-z0-9.]+\@[a-z0-9.]+\.[a-z0-9]{2,3}|(?:[a-z0-9](?:[a-z0-9-\.]*[a-z0-9])?\.(?:com|org|net|edu|us|jp)(?:\:[0-9]+)?|qmark\.tk)\b(?:(?:\/(?:\([^\s()]*\)|[^\s?.,()])*)?)/ig, function(uri) { if (/[a-z0-9.]+\@[a-z0-9.]+\.[a-z0-9]{2,3}/ig.test(uri)) { return ''+uri+''; }