-
Notifications
You must be signed in to change notification settings - Fork 27.4k
refactor($templateRequest): move $sce checks and trust the cache #12240
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -591,9 +591,8 @@ function $RouteProvider() { | |
if (angular.isFunction(templateUrl)) { | ||
templateUrl = templateUrl(nextRoute.params); | ||
} | ||
templateUrl = $sce.getTrustedResourceUrl(templateUrl); | ||
if (angular.isDefined(templateUrl)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a behavior change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
nextRoute.loadedTemplateUrl = templateUrl; | ||
nextRoute.loadedTemplateUrl = $sce.valueOf(templateUrl); | ||
template = $templateRequest(templateUrl); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1296,14 +1296,24 @@ describe('$compile', function() { | |
)); | ||
|
||
it('should not load cross domain templates by default', inject( | ||
function($compile, $rootScope, $templateCache, $sce) { | ||
function($compile, $httpBackend, $rootScope, $sce) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are both useless, you are right. Removed. |
||
expect(function() { | ||
$templateCache.put('http://example.com/should-not-load.html', 'Should not load even if in cache.'); | ||
$compile('<div class="crossDomainTemplate"></div>')($rootScope); | ||
}).toThrowMinErr('$sce', 'insecurl', 'Blocked loading resource from url not allowed by $sceDelegate policy. URL: http://example.com/should-not-load.html'); | ||
} | ||
)); | ||
|
||
it('should trust what is already in the template cache', inject( | ||
function($compile, $httpBackend, $rootScope, $templateCache, $sce) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not, I removed it. |
||
$httpBackend.expect('GET', 'http://example.com/should-not-load.html').respond('<span>example.com/remote-version</span>'); | ||
$templateCache.put('http://example.com/should-not-load.html', '<span>example.com/cached-version</span>'); | ||
element = $compile('<div class="crossDomainTemplate"></div>')($rootScope); | ||
expect(sortedHtml(element)).toEqual('<div class="crossDomainTemplate"></div>'); | ||
$rootScope.$digest(); | ||
expect(sortedHtml(element)).toEqual('<div class="crossDomainTemplate"><span>example.com/cached-version</span></div>'); | ||
} | ||
)); | ||
|
||
it('should load cross domain templates when trusted', inject( | ||
function($compile, $httpBackend, $rootScope, $sce) { | ||
$httpBackend.expect('GET', 'http://example.com/trusted-template.html').respond('<span>example.com/trusted_template_contents</span>'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: an update on the description would be nice