This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
$http - TypeError: Cannot read property 'protocol' of undefined #12925
Closed
Description
Hi,
Current version: 1.4.6.
There is a bug with $http, if you perform an undefined request (as url) cf Bug demo, the condition in urlIsSameOrigin
is false, and it creates an error hard to debug:
TypeError: Cannot read property 'protocol' of undefined
at urlIsSameOrigin (vendor.min.js:17930)
at sendReq (vendor.min.js:10507)
at $get.serverRequest (vendor.min.js:10221)
at processQueue (vendor.min.js:14678)
at vendor.min.js:14694
at Scope.$get.Scope.$eval (vendor.min.js:15922)
at Scope.$get.Scope.$digest (vendor.min.js:15733)
at Scope.$get.Scope.$apply (vendor.min.js:16030)
at done (vendor.min.js:10545)
at completeRequest (vendor.min.js:10717)
// current
function urlIsSameOrigin(requestUrl) {
var parsed = (isString(requestUrl)) ? urlResolve(requestUrl) : requestUrl;
return (parsed.protocol === originUrl.protocol &&
parsed.host === originUrl.host);
}
// Patch ?
function urlIsSameOrigin(requestUrl) {
var parsed = (isString(requestUrl) || !requestUrl) ? urlResolve(requestUrl) : requestUrl;
return (parsed.protocol === originUrl.protocol &&
parsed.host === originUrl.host);
}
Ex:
var REQUEST_LOCATION_API = urlApp.api('geo.json');
$http.get(REQUEST_LOCATION_API, {cache: true});
If REQUEST_LOCATION_API is undefined it won't works :/ but there is a request for http://localhost/
No PR because I don't know if this patch is correct.