Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 750f846

Browse files
committedDec 2, 2014
fix(linky): make urls starting with www. links
Remove line break. Change test url
1 parent c6b57f1 commit 750f846

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed
 

Diff for: ‎src/ngSanitize/filter/linky.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
*/
105105
angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) {
106106
var LINKY_URL_REGEXP =
107-
/((ftp|https?):\/\/|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"]/,
107+
/((ftp|https?):\/\/|(www\.)|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"]/,
108108
MAILTO_REGEXP = /^mailto:/;
109109

110110
return function(text, target) {
@@ -117,8 +117,10 @@ angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) {
117117
while ((match = raw.match(LINKY_URL_REGEXP))) {
118118
// We can not end in these as they are sometimes found at the end of the sentence
119119
url = match[0];
120-
// if we did not match ftp/http/mailto then assume mailto
121-
if (match[2] == match[3]) url = 'mailto:' + url;
120+
// if we did not match ftp/http/www/mailto then assume mailto
121+
if (match[2] == match[4]) {
122+
url = (url.substring(0, 4) === 'www.') ? ('http://' + url) : (url = 'mailto:' + url);
123+
}
122124
i = match.index;
123125
addText(raw.substr(0, i));
124126
addLink(url, match[0].replace(MAILTO_REGEXP, ''));

Diff for: ‎test/ngSanitize/filter/linkySpec.js

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ describe('linky', function() {
1818
expect(linky(undefined)).not.toBeDefined();
1919
});
2020

21+
it('should handle www.', function () {
22+
expect(linky('www.example.com')).toEqual('<a href="http://www.example.com">www.example.com</a>');
23+
});
24+
2125
it('should handle mailto:', function() {
2226
expect(linky("mailto:me@example.com")).
2327
toEqual('<a href="mailto:me@example.com">me@example.com</a>');

0 commit comments

Comments
 (0)