@@ -1102,7 +1102,7 @@ function $HttpProvider() {
11021102 *
11031103 * @param {string|TrustedObject } url Absolute or relative URL of the resource that is being requested;
11041104 * 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
11061106 * @returns {HttpPromise } Future object
11071107 */
11081108
@@ -1115,7 +1115,7 @@ function $HttpProvider() {
11151115 *
11161116 * @param {string|TrustedObject } url Absolute or relative URL of the resource that is being requested;
11171117 * 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
11191119 * @returns {HttpPromise } Future object
11201120 */
11211121
@@ -1128,7 +1128,7 @@ function $HttpProvider() {
11281128 *
11291129 * @param {string|TrustedObject } url Absolute or relative URL of the resource that is being requested;
11301130 * 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
11321132 * @returns {HttpPromise } Future object
11331133 */
11341134
@@ -1145,6 +1145,10 @@ function $HttpProvider() {
11451145 * {@link $sceDelegateProvider#resourceUrlWhitelist `$sceDelegateProvider.resourceUrlWhitelist`} or
11461146 * by explicitly trusting the URL via {@link $sce#trustAsResourceUrl `$sce.trustAsResourceUrl(url)`}.
11471147 *
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+ *
11481152 * JSONP requests must specify a callback to be used in the response from the server. This callback
11491153 * is passed as a query parameter in the request. You must specify the name of this parameter by
11501154 * setting the `jsonpCallbackParam` property on the request config object.
@@ -1166,7 +1170,7 @@ function $HttpProvider() {
11661170 *
11671171 * @param {string|TrustedObject } url Absolute or relative URL of the resource that is being requested;
11681172 * 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
11701174 * @returns {HttpPromise } Future object
11711175 */
11721176 createShortMethods ( 'get' , 'delete' , 'head' , 'jsonp' ) ;
@@ -1180,7 +1184,7 @@ function $HttpProvider() {
11801184 *
11811185 * @param {string } url Relative or absolute URL specifying the destination of the request
11821186 * @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
11841188 * @returns {HttpPromise } Future object
11851189 */
11861190
@@ -1193,7 +1197,7 @@ function $HttpProvider() {
11931197 *
11941198 * @param {string } url Relative or absolute URL specifying the destination of the request
11951199 * @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
11971201 * @returns {HttpPromise } Future object
11981202 */
11991203
@@ -1206,7 +1210,7 @@ function $HttpProvider() {
12061210 *
12071211 * @param {string } url Relative or absolute URL specifying the destination of the request
12081212 * @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
12101214 * @returns {HttpPromise } Future object
12111215 */
12121216 createShortMethodsWithData ( 'post' , 'put' , 'patch' ) ;
@@ -1420,20 +1424,26 @@ function $HttpProvider() {
14201424 return url ;
14211425 }
14221426
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 ) ;
14331432 }
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+ } ) ;
14341444
14351445 // Add in the JSON_CALLBACK callback param value
1436- url += ( ( url . indexOf ( '?' ) === - 1 ) ? '?' : '&' ) + key + '=JSON_CALLBACK' ;
1446+ url += ( ( url . indexOf ( '?' ) === - 1 ) ? '?' : '&' ) + cbKey + '=JSON_CALLBACK' ;
14371447
14381448 return url ;
14391449 }
0 commit comments