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

fix(linky): do not throw on non-string values #13551

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ngSanitize/filter/linky.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) {
var LINKY_URL_REGEXP =
/((ftp|https?):\/\/|(www\.)|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"\u201d\u2019]/i,
MAILTO_REGEXP = /^mailto:/i;
var isString = angular.isString;

return function(text, target, attributes) {
if (!text) return text;
if (!text || !isString(text)) return text;
var match;
var raw = text;
var html = [];
Expand Down
8 changes: 8 additions & 0 deletions test/ngSanitize/filter/linkySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ describe('linky', function() {
expect(linky(undefined)).not.toBeDefined();
});

it('should return non-string, truthy values unchanged', function() {
expect(linky(true)).toBe(true);
expect(linky(42)).toBe(42);
expect(linky([])).toEqual([]);
expect(linky({})).toEqual({});
expect(linky(noop)).toBe(noop);
});

it('should be case-insensitive', function() {
expect(linky('WWW.example.com')).toEqual('<a href="http://WWW.example.com">WWW.example.com</a>');
expect(linky('WWW.EXAMPLE.COM')).toEqual('<a href="http://WWW.EXAMPLE.COM">WWW.EXAMPLE.COM</a>');
Expand Down