Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/candy-chat/candy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weibel <mweibel@users.noreply.github.com>2015-03-25 09:26:01 +0300
committerMichael Weibel <mweibel@users.noreply.github.com>2015-03-25 09:26:01 +0300
commit9ad044bed76ab262878682d637cf2f5c7b29ae25 (patch)
tree695718b6652a0e91ee11104516b007f046c9c586
parent952bfd0f3c24a529ad368a4c884ebcf3b3da24bf (diff)
parent80ae19a29bfa040efeefe4ac45d95a26f5a5e121 (diff)
Merge pull request #380 from Sudrien/longer_linkifier
fix/improve url regex
-rw-r--r--src/util.js3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/util.js b/src/util.js
index d9810f7..fd866aa 100644
--- a/src/util.js
+++ b/src/util.js
@@ -510,6 +510,7 @@ Candy.Util = (function(self, $){
/** Function: linkify
* Replaces URLs with a HTML-link.
+ * big regex adapted from https://gist.github.com/dperini/729294 - Diego Perini, MIT license.
*
* Parameters:
* (String) text - Text to linkify
@@ -519,7 +520,7 @@ Candy.Util = (function(self, $){
*/
linkify: function(text) {
text = text.replace(/(^|[^\/])(www\.[^\.]+\.[\S]+(\b|$))/gi, '$1http://$2');
- return text.replace(/(\b(https?|ftp|file):\/\/[\-A-Z0-9+&@#\/\[\]%?=~_|!:,.;]*[\-A-Z0-9+&@#\/%=~_|])/ig, '<a href="$1" target="_blank">$1</a>');
+ return text.replace(/(\b(?:(?:https?|ftp|file):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:1\d\d|2[01]\d|22[0-3]|[1-9]\d?)(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?)/gi, '<a href="$1" target="_blank">$1</a>');
},
/** Function: escape