@@ -1099,7 +1099,7 @@ function $HttpProvider() {
1099
1099
*
1100
1100
* @param {string|TrustedObject } url Absolute or relative URL of the resource that is being requested;
1101
1101
* or an object created by a call to `$sce.trustAsResourceUrl(url)`.
1102
- * @param {Object= } config Optional configuration object
1102
+ * @param {Object= } config Optional configuration object. See https://docs.angularjs.org/api/ng/service/$http#usage
1103
1103
* @returns {HttpPromise } Future object
1104
1104
*/
1105
1105
@@ -1112,7 +1112,7 @@ function $HttpProvider() {
1112
1112
*
1113
1113
* @param {string|TrustedObject } url Absolute or relative URL of the resource that is being requested;
1114
1114
* or an object created by a call to `$sce.trustAsResourceUrl(url)`.
1115
- * @param {Object= } config Optional configuration object
1115
+ * @param {Object= } config Optional configuration object. See https://docs.angularjs.org/api/ng/service/$http#usage
1116
1116
* @returns {HttpPromise } Future object
1117
1117
*/
1118
1118
@@ -1125,7 +1125,7 @@ function $HttpProvider() {
1125
1125
*
1126
1126
* @param {string|TrustedObject } url Absolute or relative URL of the resource that is being requested;
1127
1127
* or an object created by a call to `$sce.trustAsResourceUrl(url)`.
1128
- * @param {Object= } config Optional configuration object
1128
+ * @param {Object= } config Optional configuration object. See https://docs.angularjs.org/api/ng/service/$http#usage
1129
1129
* @returns {HttpPromise } Future object
1130
1130
*/
1131
1131
@@ -1142,6 +1142,10 @@ function $HttpProvider() {
1142
1142
* {@link $sceDelegateProvider#resourceUrlWhitelist `$sceDelegateProvider.resourceUrlWhitelist`} or
1143
1143
* by explicitly trusting the URL via {@link $sce#trustAsResourceUrl `$sce.trustAsResourceUrl(url)`}.
1144
1144
*
1145
+ * You should avoid generating the URL for the JSONP request from user provided data.
1146
+ * Provide additional query parameters via `params` property of the `config` parameter, rather than
1147
+ * modifying the URL itself.
1148
+ *
1145
1149
* JSONP requests must specify a callback to be used in the response from the server. This callback
1146
1150
* is passed as a query parameter in the request. You must specify the name of this parameter by
1147
1151
* setting the `jsonpCallbackParam` property on the request config object.
@@ -1163,7 +1167,7 @@ function $HttpProvider() {
1163
1167
*
1164
1168
* @param {string|TrustedObject } url Absolute or relative URL of the resource that is being requested;
1165
1169
* or an object created by a call to `$sce.trustAsResourceUrl(url)`.
1166
- * @param {Object= } config Optional configuration object
1170
+ * @param {Object= } config Optional configuration object. See https://docs.angularjs.org/api/ng/service/$http#usage
1167
1171
* @returns {HttpPromise } Future object
1168
1172
*/
1169
1173
createShortMethods ( 'get' , 'delete' , 'head' , 'jsonp' ) ;
@@ -1177,7 +1181,7 @@ function $HttpProvider() {
1177
1181
*
1178
1182
* @param {string } url Relative or absolute URL specifying the destination of the request
1179
1183
* @param {* } data Request content
1180
- * @param {Object= } config Optional configuration object
1184
+ * @param {Object= } config Optional configuration object. See https://docs.angularjs.org/api/ng/service/$http#usage
1181
1185
* @returns {HttpPromise } Future object
1182
1186
*/
1183
1187
@@ -1190,7 +1194,7 @@ function $HttpProvider() {
1190
1194
*
1191
1195
* @param {string } url Relative or absolute URL specifying the destination of the request
1192
1196
* @param {* } data Request content
1193
- * @param {Object= } config Optional configuration object
1197
+ * @param {Object= } config Optional configuration object. See https://docs.angularjs.org/api/ng/service/$http#usage
1194
1198
* @returns {HttpPromise } Future object
1195
1199
*/
1196
1200
@@ -1203,7 +1207,7 @@ function $HttpProvider() {
1203
1207
*
1204
1208
* @param {string } url Relative or absolute URL specifying the destination of the request
1205
1209
* @param {* } data Request content
1206
- * @param {Object= } config Optional configuration object
1210
+ * @param {Object= } config Optional configuration object. See https://docs.angularjs.org/api/ng/service/$http#usage
1207
1211
* @returns {HttpPromise } Future object
1208
1212
*/
1209
1213
createShortMethodsWithData ( 'post' , 'put' , 'patch' ) ;
@@ -1417,20 +1421,26 @@ function $HttpProvider() {
1417
1421
return url ;
1418
1422
}
1419
1423
1420
- function sanitizeJsonpCallbackParam ( url , key ) {
1421
- if ( / [ & ? ] [ ^ = ] + = J S O N _ C A L L B A C K / . test ( url ) ) {
1422
- // Throw if the url already contains a reference to JSON_CALLBACK
1423
- throw $httpMinErr ( 'badjsonp' , 'Illegal use of JSON_CALLBACK in url, "{0}"' , url ) ;
1424
- }
1425
-
1426
- var callbackParamRegex = new RegExp ( '[&?]' + key + '=' ) ;
1427
- if ( callbackParamRegex . test ( url ) ) {
1428
- // Throw if the callback param was already provided
1429
- throw $httpMinErr ( 'badjsonp' , 'Illegal use of callback param, "{0}", in url, "{1}"' , key , url ) ;
1424
+ function sanitizeJsonpCallbackParam ( url , cbKey ) {
1425
+ var parts = url . split ( '?' ) ;
1426
+ if ( parts . length > 2 ) {
1427
+ // Throw if the url contains more than one `?` query indicator
1428
+ throw $httpMinErr ( 'badjsonp' , 'Illegal use more than one "?", in url, "{1}"' , url ) ;
1430
1429
}
1430
+ var params = parseKeyValue ( parts [ 1 ] ) ;
1431
+ forEach ( params , function ( value , key ) {
1432
+ if ( value === 'JSON_CALLBACK' ) {
1433
+ // Throw if the url already contains a reference to JSON_CALLBACK
1434
+ throw $httpMinErr ( 'badjsonp' , 'Illegal use of JSON_CALLBACK in url, "{0}"' , url ) ;
1435
+ }
1436
+ if ( key === cbKey ) {
1437
+ // Throw if the callback param was already provided
1438
+ throw $httpMinErr ( 'badjsonp' , 'Illegal use of callback param, "{0}", in url, "{1}"' , cbKey , url ) ;
1439
+ }
1440
+ } ) ;
1431
1441
1432
1442
// Add in the JSON_CALLBACK callback param value
1433
- url += ( ( url . indexOf ( '?' ) === - 1 ) ? '?' : '&' ) + key + '=JSON_CALLBACK' ;
1443
+ url += ( ( url . indexOf ( '?' ) === - 1 ) ? '?' : '&' ) + cbKey + '=JSON_CALLBACK' ;
1434
1444
1435
1445
return url ;
1436
1446
}
0 commit comments