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

Commit 25d72c4

Browse files
SQUASH ME: feat($http): specify the JSONP callback via the jsonpCallbackParam config value
1 parent 022fc44 commit 25d72c4

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

docs/content/error/$http/badjsonp.ngdoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
This error occurs when the URL generated from the configuration object contains a parameter with the same name as the configured `jsonpCallbackParam`
77
property; or when it contains a parameter whose value is `JSON_CALLBACK`.
88

9-
`$http` JSON requests need to attach a callback query parameter to the URL. The name of this parameter is specified in the configuration
9+
`$http` JSONP requests need to attach a callback query parameter to the URL. The name of this parameter is specified in the configuration
1010
object (or in the defaults) via the `jsonpCallbackParam` property. You must not provide your own parameter with this name in the configuration
1111
of the request.
1212

src/ng/http.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ function $HttpProvider() {
287287
* Defaults to {@link ng.$httpParamSerializer $httpParamSerializer}.
288288
*
289289
* - **`defaults.jsonpCallbackParam`** - `{string} - the name of the query parameter that passes the callback in a JSONP
290-
* request. The value of this parameter will be replaced with the expression generated by the {@link jsonpCallbacks}
290+
* request. The value of this parameter will be replaced with the expression generated by the {@link $jsonpCallbacks}
291291
* service. Defaults to `'callback'`.
292292
*
293293
**/
@@ -1169,22 +1169,22 @@ function $HttpProvider() {
11691169
* @description
11701170
* Shortcut method to perform `JSONP` request.
11711171
*
1172-
* Note that, since JSONP requests are sensitive because the response is given full acces to the browser,
1172+
* Note that, since JSONP requests are sensitive because the response is given full access to the browser,
11731173
* the url must be declared, via {@link $sce} as a trusted resource URL.
11741174
* You can trust a URL by adding it to the whitelist via
11751175
* {@link $sceDelegateProvider#resourceUrlWhitelist `$sceDelegateProvider.resourceUrlWhitelist`} or
1176-
* by explicitly trusted the URL via {@link $sce#trustAsResourceUrl `$sce.trustAsResourceUrl(url)`}.
1176+
* by explicitly trusting the URL via {@link $sce#trustAsResourceUrl `$sce.trustAsResourceUrl(url)`}.
11771177
*
11781178
* JSONP requests must specify a callback to be used in the response from the server. This callback
1179-
* is passed as as a query parameter in the request. You must specify the name of this parameter by
1179+
* is passed as a query parameter in the request. You must specify the name of this parameter by
11801180
* setting the `jsonpCallbackParam` property on the request config object.
11811181
*
11821182
* ```
11831183
* $http.jsonp('some/trusted/url', {jsonpCallbackParam: 'callback'})
11841184
* ```
11851185
*
11861186
* You can also specify a global callback parameter key in `$http.defaults.jsonpCallbackParam`.
1187-
* By default this is set to `callback`.
1187+
* By default this is set to `'callback'`.
11881188
*
11891189
* <div class="alert alert-danger">
11901190
* You can no longer use the `JSON_CALLBACK` string as a placeholder for specifying where the callback
@@ -1454,7 +1454,7 @@ function $HttpProvider() {
14541454
throw $httpMinErr('badjsonp', 'Illegal use of JSON_CALLBACK in url, "{0}"', url);
14551455
}
14561456

1457-
var callbackParamRegex = new RegExp('([&?]' + key + '=)');
1457+
var callbackParamRegex = new RegExp('[&?]' + key + '=');
14581458
if (callbackParamRegex.test(url)) {
14591459
// Throw if the callback param was already provided
14601460
throw $httpMinErr('badjsonp', 'Illegal use of callback param, "{0}", in url, "{1}"', key, url);

test/ng/httpSpec.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,8 @@ describe('$http', function() {
326326
});
327327

328328
it('should accept a $sce trusted object for the request configuration url', function() {
329-
expect(function() {
330-
$httpBackend.expect('GET', '/url').respond('');
331-
$http({url: $sce.trustAsResourceUrl('/url')});
332-
}).not.toThrowMinErr('$http','badreq', 'Http request configuration url must be a string. Received: false');
329+
$httpBackend.expect('GET', '/url').respond('');
330+
$http({url: $sce.trustAsResourceUrl('/url')});
333331
});
334332

335333
it('should send GET requests if no method specified', function() {

0 commit comments

Comments
 (0)