From 237725367602738f9164b4456b9cc3cb145643c6 Mon Sep 17 00:00:00 2001 From: David Cormier Date: Sun, 13 Oct 2013 15:14:43 -0400 Subject: [PATCH] plugins: fix imagePlugin --- js/plugins.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/js/plugins.js b/js/plugins.js index eeaf829..6fa5061 100644 --- a/js/plugins.js +++ b/js/plugins.js @@ -110,6 +110,8 @@ plugins.service('plugins', ['userPlugins', '$sce', function(userPlugins, $sce) */ plugins.factory('userPlugins', function() { + var urlRegexp = RegExp(/(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/); + var youtubePlugin = new Plugin(function(message) { if (message.indexOf('youtube.com') != -1) { @@ -123,8 +125,7 @@ plugins.factory('userPlugins', function() { youtubePlugin.name = 'youtube video'; var urlPlugin = new Plugin(function(message) { - var urlPattern = /(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/; - var url = message.match(urlPattern); + var url = message.match(urlRegexp); if (url) { return '' + message + ''; } @@ -134,10 +135,14 @@ plugins.factory('userPlugins', function() { urlPlugin.name = 'url'; var imagePlugin = new Plugin(function(message) { - var urls = message.match(/https?:\/\/[^\s]*\.(jpg|png|gif)\b/) - if (urls != null) { - var url = urls[0]; /* Actually parse one url per message */ - return ''; + + var url = message.match(urlRegexp); + + if (url) { + var url = url[0]; /* Actually parse one url per message */ + if (url.match(/png$|gif$|jpg$|jpeg$/)) { + return ''; + } } return null; });