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