Skip to content

Commit 5f76bc6

Browse files
XFreeNarretz
authored andcommitted
feat($sanitize, $compileProvider, linky): add support for the "sftp" protocol in links
Add support for the sftp protocol in the linky filter and the "aHrefSanitizationWhitelist" that is used by $sanitize and can be configured in the $compileProvider. Closes angular#16102
1 parent c8d3498 commit 5f76bc6

File tree

6 files changed

+13
-5
lines changed

6 files changed

+13
-5
lines changed

src/ng/sanitizeUri.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Private service to sanitize uris for links and images. Used by $compile and $sanitize.
77
*/
88
function $$SanitizeUriProvider() {
9-
var aHrefSanitizationWhitelist = /^\s*(https?|ftp|mailto|tel|file):/,
9+
var aHrefSanitizationWhitelist = /^\s*(https?|s?ftp|mailto|tel|file):/,
1010
imgSrcSanitizationWhitelist = /^\s*((https?|ftp|file|blob):|data:image\/)/;
1111

1212
/**

src/ngSanitize/filter/linky.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @kind function
77
*
88
* @description
9-
* Finds links in text input and turns them into html links. Supports `http/https/ftp/mailto` and
9+
* Finds links in text input and turns them into html links. Supports `http/https/ftp/sftp/mailto` and
1010
* plain email address links.
1111
*
1212
* Requires the {@link ngSanitize `ngSanitize`} module to be installed.
@@ -129,7 +129,7 @@
129129
*/
130130
angular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) {
131131
var LINKY_URL_REGEXP =
132-
/((ftp|https?):\/\/|(www\.)|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"\u201d\u2019]/i,
132+
/((s?ftp|https?):\/\/|(www\.)|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"\u201d\u2019]/i,
133133
MAILTO_REGEXP = /^mailto:/i;
134134

135135
var linkyMinErr = angular.$$minErr('linky');

test/ng/compileSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describe('$compile', function() {
153153

154154
it('should allow aHrefSanitizationWhitelist to be configured', function() {
155155
module(function($compileProvider) {
156-
expect($compileProvider.aHrefSanitizationWhitelist()).toEqual(/^\s*(https?|ftp|mailto|tel|file):/); // the default
156+
expect($compileProvider.aHrefSanitizationWhitelist()).toEqual(/^\s*(https?|s?ftp|mailto|tel|file):/); // the default
157157
$compileProvider.aHrefSanitizationWhitelist(/other/);
158158
expect($compileProvider.aHrefSanitizationWhitelist()).toEqual(/other/);
159159
});

test/ng/sanitizeUriSpec.js

+3
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ describe('sanitizeUri', function() {
216216
testUrl = 'ftp://foo/bar';
217217
expect(sanitizeHref(testUrl)).toBe('ftp://foo/bar');
218218

219+
testUrl = 'sftp://foo/bar';
220+
expect(sanitizeHref(testUrl)).toBe('sftp://foo/bar');
221+
219222
testUrl = 'mailto:[email protected]';
220223
expect(sanitizeHref(testUrl)).toBe('mailto:[email protected]');
221224

test/ngSanitize/filter/linkySpec.js

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ describe('linky', function() {
5858
expect(linky('HTTP://example.com')).toEqual('<a href="HTTP://example.com">HTTP://example.com</a>');
5959
expect(linky('HTTPS://www.example.com')).toEqual('<a href="HTTPS://www.example.com">HTTPS://www.example.com</a>');
6060
expect(linky('HTTPS://example.com')).toEqual('<a href="HTTPS://example.com">HTTPS://example.com</a>');
61+
expect(linky('FTP://www.example.com')).toEqual('<a href="FTP://www.example.com">FTP://www.example.com</a>');
62+
expect(linky('FTP://example.com')).toEqual('<a href="FTP://example.com">FTP://example.com</a>');
63+
expect(linky('SFTP://www.example.com')).toEqual('<a href="SFTP://www.example.com">SFTP://www.example.com</a>');
64+
expect(linky('SFTP://example.com')).toEqual('<a href="SFTP://example.com">SFTP://example.com</a>');
6165
});
6266

6367
it('should handle www.', function() {

test/ngSanitize/sanitizeSpec.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ describe('HTML', function() {
270270

271271
// See https://github.com/cure53/DOMPurify/blob/a992d3a75031cb8bb032e5ea8399ba972bdf9a65/src/purify.js#L439-L449
272272
it('should not allow JavaScript execution when creating inert document', inject(function($sanitize) {
273-
var doc = $sanitize('<svg><g onload="window.xxx = 100"></g></svg>');
273+
$sanitize('<svg><g onload="window.xxx = 100"></g></svg>');
274+
274275
expect(window.xxx).toBe(undefined);
275276
delete window.xxx;
276277
}));

0 commit comments

Comments
 (0)