From 2dafbb229ea2ef011361a9cd8bd636e7ed849973 Mon Sep 17 00:00:00 2001 From: chasefleming Date: Mon, 1 Dec 2014 17:33:53 -0800 Subject: [PATCH] fix(linky): make urls starting with www. links Remove line break. Change test url Remove space Minor tweak --- src/ngSanitize/filter/linky.js | 8 +++++--- test/ngSanitize/filter/linkySpec.js | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ngSanitize/filter/linky.js b/src/ngSanitize/filter/linky.js index 7a6538937c88..d959de6742fb 100644 --- a/src/ngSanitize/filter/linky.js +++ b/src/ngSanitize/filter/linky.js @@ -104,7 +104,7 @@ */ angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) { var LINKY_URL_REGEXP = - /((ftp|https?):\/\/|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"]/, + /((ftp|https?):\/\/|(www\.)|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"]/, MAILTO_REGEXP = /^mailto:/; return function(text, target) { @@ -117,8 +117,10 @@ angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) { while ((match = raw.match(LINKY_URL_REGEXP))) { // We can not end in these as they are sometimes found at the end of the sentence url = match[0]; - // if we did not match ftp/http/mailto then assume mailto - if (match[2] == match[3]) url = 'mailto:' + url; + // if we did not match ftp/http/www/mailto then assume mailto + if (!match[2] && !match[4]) { + url = (match[3] ? 'http://' : 'mailto:') + url; + } i = match.index; addText(raw.substr(0, i)); addLink(url, match[0].replace(MAILTO_REGEXP, '')); diff --git a/test/ngSanitize/filter/linkySpec.js b/test/ngSanitize/filter/linkySpec.js index fc442e4cd203..ab06bde84df2 100644 --- a/test/ngSanitize/filter/linkySpec.js +++ b/test/ngSanitize/filter/linkySpec.js @@ -18,6 +18,10 @@ describe('linky', function() { expect(linky(undefined)).not.toBeDefined(); }); + it('should handle www.', function() { + expect(linky('www.example.com')).toEqual('www.example.com'); + }); + it('should handle mailto:', function() { expect(linky("mailto:me@example.com")). toEqual('me@example.com');