Skip to content

Commit

Permalink
Fix link detection
Browse files Browse the repository at this point in the history
We shouldn't consume the trailing space,
otherwise the next link has no leading space

Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen authored and Backportbot committed Jul 22, 2019
1 parent 3e2c5c2 commit 8211744
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 8211744

Please sign in to comment.