Skip to content

Commit

Permalink
Merge pull request #2034 from nextcloud/backport/2031/stable16
Browse files Browse the repository at this point in the history
[stable16] Fix link detection
  • Loading branch information
nickvergessen authored Jul 22, 2019
2 parents 3e2c5c2 + 8211744 commit 07b34c3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions js/views/chatview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
});
},

Expand Down

0 comments on commit 07b34c3

Please sign in to comment.