From 8211744b20b3e2e767b4f4d568ba193a6155be61 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Jul 2019 15:04:31 +0200 Subject: [PATCH] Fix link detection We shouldn't consume the trailing space, otherwise the next link has no leading space Signed-off-by: Joas Schilling --- js/views/chatview.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/js/views/chatview.js b/js/views/chatview.js index 16788817422..df1cdcf265c 100644 --- a/js/views/chatview.js +++ b/js/views/chatview.js @@ -458,11 +458,12 @@ * copied from OCP.Comments and adjusted accordingly. */ // var urlRegex = /(\s|^)(https?:\/\/)?((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|$)/ig; - var urlRegex = /(\s|^)(https?:\/\/)((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(\s|$)/ig; - return message.replace(urlRegex, function (_, leadingSpace, protocol, url, trailingSpace) { + var urlRegex = /(\s|^)(https?:\/\/)((?:[-A-Z0-9+_]+\.)+[-A-Z]+(?:\/[-A-Z0-9+&@#%?=~_|!:,.;()]*)*)(?=\s|$)/ig; + return message.replace(urlRegex, function (_, leadingSpace, protocol, url) { + var trailingClosingBracket = ''; if (url.substr(-1) === ')' && url.indexOf('(') === -1) { url = url.substr(0, url.length - 1); - trailingSpace = ')' + trailingSpace; + trailingClosingBracket = ')'; } var linkText = url; // if (!protocol) { @@ -472,7 +473,7 @@ linkText = protocol + url; } - return leadingSpace + '' + linkText + '' + trailingSpace; + return leadingSpace + '' + linkText + '' + trailingClosingBracket; }); },