From 8768fa0c30ab73f01bce761593c01008688a7bb6 Mon Sep 17 00:00:00 2001
From: Darren <darren@darrenwhitlen.com>
Date: Sat, 18 Oct 2014 13:28:16 +0100
Subject: [PATCH] Links are only valid if the *whole* word is a URL

---
 client/src/views/channel.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/client/src/views/channel.js b/client/src/views/channel.js
index f3d1ac9..a7c33c5 100644
--- a/client/src/views/channel.js
+++ b/client/src/views/channel.js
@@ -201,7 +201,7 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
         var found_a_url = false,
             parsed_url;
 
-        parsed_url = word.replace(/(([A-Za-z][A-Za-z0-9\-]*\:\/\/)|(www\.))([\w.\-]+)([a-zA-Z]{2,6})(:[0-9]+)?(\/[\w#!:.?$'()[\]*,;~+=&%@!\-\/]*)?/gi, function (url) {
+        parsed_url = word.replace(/^(([A-Za-z][A-Za-z0-9\-]*\:\/\/)|(www\.))([\w.\-]+)([a-zA-Z]{2,6})(:[0-9]+)?(\/[\w!:.?$'()[\]*,;~+=&%@!\-\/]*)?(#.*)?$/gi, function (url) {
             var nice = url,
                 extra_html = '';
 
@@ -226,7 +226,7 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({
             extra_html = _kiwi.view.MediaMessage.buildHtml(url);
 
             // Make the link clickable
-            return '<a class="link_ext" target="_blank" rel="nofollow" href="' + url + '">' + nice + '</a>' + extra_html;
+            return '<a class="link_ext" target="_blank" rel="nofollow" href="' + url.replace(/"/g, '%22') + '">' + _.escape(nice) + '</a>' + extra_html;
         });
 
         return found_a_url ? parsed_url : false;
-- 
2.25.1