@@ -155,12 +155,14 @@ function shallowClearAndCopy(src, dst) {
155
155
* with `http response` object. See {@link ng.$http $http interceptors}.
156
156
*
157
157
* @param {Object } options Hash with custom settings that should extend the
158
- * default `$resourceProvider` behavior. The only supported option is
158
+ * default `$resourceProvider` behavior.
159
159
*
160
160
* Where:
161
161
*
162
162
* - **`stripTrailingSlashes`** – {boolean} – If true then the trailing
163
163
* slashes from any calculated URL will be stripped. (Defaults to true.)
164
+ * - **`encodeSlashes`** - {boolean} - If true then slashes in URL parameters
165
+ * will be encoded. (Defaults to true.)
164
166
*
165
167
* @returns {Object } A resource "class" object with methods for the default set of resource actions
166
168
* optionally extended with custom `actions`. The default set contains these actions:
@@ -344,6 +346,9 @@ angular.module('ngResource', ['ng']).
344
346
// Strip slashes by default
345
347
stripTrailingSlashes : true ,
346
348
349
+ // Encode slashes by default
350
+ encodeSlashes : true ,
351
+
347
352
// Default actions configuration
348
353
actions : {
349
354
'get' : { method : 'GET' } ,
@@ -373,8 +378,8 @@ angular.module('ngResource', ['ng']).
373
378
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
374
379
* / "*" / "+" / "," / ";" / "="
375
380
*/
376
- function encodeUriSegment ( val ) {
377
- return encodeUriQuery ( val , true ) .
381
+ function encodeUriSegment ( val , encodeSlashes ) {
382
+ return encodeUriQuery ( val , true , encodeSlashes ) .
378
383
replace ( / % 2 6 / gi, '&' ) .
379
384
replace ( / % 3 D / gi, '=' ) .
380
385
replace ( / % 2 B / gi, '+' ) ;
@@ -392,12 +397,13 @@ angular.module('ngResource', ['ng']).
392
397
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
393
398
* / "*" / "+" / "," / ";" / "="
394
399
*/
395
- function encodeUriQuery ( val , pctEncodeSpaces ) {
400
+ function encodeUriQuery ( val , pctEncodeSpaces , encodeSlashes ) {
396
401
return encodeURIComponent ( val ) .
397
402
replace ( / % 4 0 / gi, '@' ) .
398
403
replace ( / % 3 A / gi, ':' ) .
399
404
replace ( / % 2 4 / g, '$' ) .
400
405
replace ( / % 2 C / gi, ',' ) .
406
+ replace ( / % 2 F / g, ( encodeSlashes ? '%2F' : '/' ) ) .
401
407
replace ( / % 2 0 / g, ( pctEncodeSpaces ? '%20' : '+' ) ) ;
402
408
}
403
409
@@ -430,7 +436,7 @@ angular.module('ngResource', ['ng']).
430
436
forEach ( self . urlParams , function ( _ , urlParam ) {
431
437
val = params . hasOwnProperty ( urlParam ) ? params [ urlParam ] : self . defaults [ urlParam ] ;
432
438
if ( angular . isDefined ( val ) && val !== null ) {
433
- encodedVal = encodeUriSegment ( val ) ;
439
+ encodedVal = encodeUriSegment ( val , self . defaults . encodeSlashes ) ;
434
440
url = url . replace ( new RegExp ( ":" + urlParam + "(\\W|$)" , "g" ) , function ( match , p1 ) {
435
441
return encodedVal + p1 ;
436
442
} ) ;
0 commit comments