-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($templateRequest): ignore JSON Content-Type header and content #9619
Changes from all 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 |
---|---|---|
|
@@ -25,7 +25,23 @@ function $TemplateRequestProvider() { | |
var self = handleRequestFn; | ||
self.totalPendingRequests++; | ||
|
||
return $http.get(tpl, { cache : $templateCache }) | ||
var transformResponse = $http.defaults && $http.defaults.transformResponse; | ||
var idx; | ||
|
||
if (isArray(transformResponse) && | ||
(idx = transformResponse.indexOf(httpResponseTransform)) >= 0) { | ||
transformResponse = copy(transformResponse, []); | ||
transformResponse.splice(idx, 1); | ||
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. Why not just slice it (instead of copy + splice) ? 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. slice would only work if the item to be removed is at the very beginning or very end of the array 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. There is no guarantee of this, even if it is the common case 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. since you are doing 3 "heavy" array operations (indexof, copy, splice), it might be better to just have one for loop to manually copy stuff over except for the default transform |
||
} else if (transformResponse === httpResponseTransform) { | ||
transformResponse = null; | ||
} | ||
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. updated to avoid breaking change |
||
|
||
var httpOptions = { | ||
cache: $templateCache, | ||
transformResponse: transformResponse | ||
}; | ||
|
||
return $http.get(tpl, httpOptions) | ||
.then(function(response) { | ||
var html = response.data; | ||
if(!html || html.length === 0) { | ||
|
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.
please rename to
defaultHttpResponseTransform