Files
angular.js/test/ng/directive/ngSrcsetSpec.js
ltrillaud ab80cd9066 fix(compile): sanitize srcset attribute
Applies similar sanitization as is applie to img[src] to img[srcset],
while adapting to the different semantics and syntax of srcset.
2014-09-30 16:32:58 -07:00

33 lines
1.2 KiB
JavaScript

/*jshint scripturl:true*/
'use strict';
describe('ngSrcset', function() {
var element;
afterEach(function() {
dealoc(element);
});
it('should not result empty string in img srcset', inject(function($rootScope, $compile) {
$rootScope.image = {};
element = $compile('<img ng-srcset="{{image.url}} 2x">')($rootScope);
$rootScope.$digest();
expect(element.attr('srcset')).toBeUndefined();
}));
it('should sanitize good urls', inject(function($rootScope, $compile) {
$rootScope.imageUrl = 'http://example.com/image1.png 1x, http://example.com/image2.png 2x';
element = $compile('<img ng-srcset="{{imageUrl}}">')($rootScope);
$rootScope.$digest();
expect(element.attr('srcset')).toBe('http://example.com/image1.png 1x,http://example.com/image2.png 2x');
}));
it('should sanitize evil url', inject(function($rootScope, $compile) {
$rootScope.imageUrl = 'http://example.com/image1.png 1x, javascript:doEvilStuff() 2x';
element = $compile('<img ng-srcset="{{imageUrl}}">')($rootScope);
$rootScope.$digest();
expect(element.attr('srcset')).toBe('http://example.com/image1.png 1x,unsafe:javascript:doEvilStuff() 2x');
}));
});