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

fix($templateRequest): ignore JSON Content-Type header and content #9619

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion src/ng/templateRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ var $compileMinErr = minErr('$compile');
*/
function $TemplateRequestProvider() {
this.$get = ['$templateCache', '$http', '$q', function($templateCache, $http, $q) {
var httpOptions = {
cache: $templateCache,
transformResponse: null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be a breaking change. can't we just identify the default transform and remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be a bigger change, but yes we can do that.

};

function handleRequestFn(tpl, ignoreRequestError) {
var self = handleRequestFn;
self.totalPendingRequests++;

return $http.get(tpl, { cache : $templateCache })
return $http.get(tpl, httpOptions)
.then(function(response) {
var html = response.data;
if(!html || html.length === 0) {
Expand Down
11 changes: 11 additions & 0 deletions test/ng/templateRequestSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,15 @@ describe('$templateRequest', function() {
expect($templateRequest.totalPendingRequests).toBe(0);
}));

it('should not try to parse a response as JSON',
inject(function($templateRequest, $httpBackend) {
var spy = jasmine.createSpy('success');
$httpBackend.expectGET('a.html').respond('{{text}}', {
'Content-Type': 'application/json'
});
$templateRequest('a.html').then(spy);
$httpBackend.flush();
expect(spy).toHaveBeenCalledOnce();
expect(spy.argsForCall[0][0]).toBe('{{text}}');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toHaveBeenCalledOnceWith('{{text}}')

}));
});