urlplugin: fix regex

This commit is contained in:
Tristan Matthews 2013-10-01 21:20:49 -04:00 committed by David Cormier
parent ab490074d3
commit 5168b833cb

View file

@ -149,11 +149,10 @@ weechat.factory('youtubePlugin', [function() {
weechat.factory('urlPlugin', [function() {
var contentForMessage = function(message) {
var prefix = 'http://';
var linkIndex = message.indexOf(prefix);
if (linkIndex != -1) {
var token = message.substr(linkIndex);
return '<a href="' + token + '">' + token + '</a>';
var urlPattern = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&amp;:\/~+#-]*[\w@?^=%&amp;\/~+#-])?/;
var url = message.match(urlPattern);
if (url) {
return '<a href="' + url[0] + '">' + message + '</a>';
}
return null;
}