diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2019-07-22 17:35:50 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-22 17:35:50 +0300 |
commit | 07b34c37ae6bb8b53c39f1cd073682644caf5878 (patch) | |
tree | 597ab3efbb25e9a99df0e7f146cc1de517cc6f7a | |
parent | 3e2c5c2123438ec13d52359f5be09c7965784745 (diff) | |
parent | 8211744b20b3e2e767b4f4d568ba193a6155be61 (diff) |
Merge pull request #2034 from nextcloud/backport/2031/stable16
[stable16] Fix link detection
-rw-r--r-- | js/views/chatview.js | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/js/views/chatview.js b/js/views/chatview.js index 167888174..df1cdcf26 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 + '<a class="external" target="_blank" rel="noopener noreferrer" href="' + protocol + url + '">' + linkText + '</a>' + trailingSpace; + return leadingSpace + '<a class="external" target="_blank" rel="noopener noreferrer" href="' + protocol + url + '">' + linkText + '</a>' + trailingClosingBracket; }); }, |