1
1
/**
2
- * @license AngularJS v1.0.3
2
+ * @license AngularJS v1.0.4
3
3
* (c) 2010-2012 Google, Inc. http://angularjs.org
4
4
* License: MIT
5
5
*/
12
12
* @description
13
13
*/
14
14
15
- /**
15
+ /**
16
16
* @ngdoc object
17
17
* @name ngResource.$resource
18
18
* @requires $http
25
25
* the need to interact with the low level {@link ng.$http $http} service.
26
26
*
27
27
* @param {string } url A parameterized URL template with parameters prefixed by `:` as in
28
- * `/user/:username`.
28
+ * `/user/:username`. If you are using a URL with a port number (e.g.
29
+ * `http://example.com:8080/api`), you'll need to escape the colon character before the port
30
+ * number, like this: `$resource('http://example.com\\:8080/api')`.
29
31
*
30
32
* @param {Object= } paramDefaults Default values for `url` parameters. These can be overridden in
31
33
* `actions` methods.
@@ -230,46 +232,46 @@ angular.module('ngResource', ['ng']).
230
232
return $parse ( path ) ( obj ) ;
231
233
} ;
232
234
233
- /**
234
- * We need our custom mehtod because encodeURIComponent is too aggressive and doesn't follow
235
- * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
236
- * segments:
237
- * segment = *pchar
238
- * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
239
- * pct-encoded = "%" HEXDIG HEXDIG
240
- * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
241
- * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
242
- * / "*" / "+" / "," / ";" / "="
243
- */
244
- function encodeUriSegment ( val ) {
245
- return encodeUriQuery ( val , true ) .
246
- replace ( / % 2 6 / gi, '&' ) .
247
- replace ( / % 3 D / gi, '=' ) .
248
- replace ( / % 2 B / gi, '+' ) ;
249
- }
250
-
251
-
252
- /**
253
- * This method is intended for encoding *key* or *value* parts of query component. We need a custom
254
- * method becuase encodeURIComponent is too agressive and encodes stuff that doesn't have to be
255
- * encoded per http://tools.ietf.org/html/rfc3986:
256
- * query = *( pchar / "/" / "?" )
257
- * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
258
- * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
259
- * pct-encoded = "%" HEXDIG HEXDIG
260
- * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
261
- * / "*" / "+" / "," / ";" / "="
262
- */
263
- function encodeUriQuery ( val , pctEncodeSpaces ) {
264
- return encodeURIComponent ( val ) .
265
- replace ( / % 4 0 / gi, '@' ) .
266
- replace ( / % 3 A / gi, ':' ) .
267
- replace ( / % 2 4 / g, '$' ) .
268
- replace ( / % 2 C / gi, ',' ) .
269
- replace ( ( pctEncodeSpaces ? null : / % 2 0 / g) , '+' ) ;
270
- }
271
-
272
- function Route ( template , defaults ) {
235
+ /**
236
+ * We need our custom method because encodeURIComponent is too aggressive and doesn't follow
237
+ * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
238
+ * segments:
239
+ * segment = *pchar
240
+ * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
241
+ * pct-encoded = "%" HEXDIG HEXDIG
242
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
243
+ * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
244
+ * / "*" / "+" / "," / ";" / "="
245
+ */
246
+ function encodeUriSegment ( val ) {
247
+ return encodeUriQuery ( val , true ) .
248
+ replace ( / % 2 6 / gi, '&' ) .
249
+ replace ( / % 3 D / gi, '=' ) .
250
+ replace ( / % 2 B / gi, '+' ) ;
251
+ }
252
+
253
+
254
+ /**
255
+ * This method is intended for encoding *key* or *value* parts of query component. We need a custom
256
+ * method becuase encodeURIComponent is too agressive and encodes stuff that doesn't have to be
257
+ * encoded per http://tools.ietf.org/html/rfc3986:
258
+ * query = *( pchar / "/" / "?" )
259
+ * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
260
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
261
+ * pct-encoded = "%" HEXDIG HEXDIG
262
+ * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
263
+ * / "*" / "+" / "," / ";" / "="
264
+ */
265
+ function encodeUriQuery ( val , pctEncodeSpaces ) {
266
+ return encodeURIComponent ( val ) .
267
+ replace ( / % 4 0 / gi, '@' ) .
268
+ replace ( / % 3 A / gi, ':' ) .
269
+ replace ( / % 2 4 / g, '$' ) .
270
+ replace ( / % 2 C / gi, ',' ) .
271
+ replace ( ( pctEncodeSpaces ? null : / % 2 0 / g) , '+' ) ;
272
+ }
273
+
274
+ function Route ( template , defaults ) {
273
275
this . template = template = template + '#' ;
274
276
this . defaults = defaults || { } ;
275
277
var urlParams = this . urlParams = { } ;
@@ -295,7 +297,14 @@ angular.module('ngResource', ['ng']).
295
297
encodedVal = encodeUriSegment ( val ) ;
296
298
url = url . replace ( new RegExp ( ":" + urlParam + "(\\W)" , "g" ) , encodedVal + "$1" ) ;
297
299
} else {
298
- url = url . replace ( new RegExp ( "/?:" + urlParam + "(\\W)" , "g" ) , '$1' ) ;
300
+ url = url . replace ( new RegExp ( "(\/?):" + urlParam + "(\\W)" , "g" ) , function ( match ,
301
+ leadingSlashes , tail ) {
302
+ if ( tail . charAt ( 0 ) == '/' ) {
303
+ return tail ;
304
+ } else {
305
+ return leadingSlashes + tail ;
306
+ }
307
+ } ) ;
299
308
}
300
309
} ) ;
301
310
url = url . replace ( / \/ ? # $ / , '' ) ;
@@ -331,6 +340,7 @@ angular.module('ngResource', ['ng']).
331
340
}
332
341
333
342
forEach ( actions , function ( action , name ) {
343
+ action . method = angular . uppercase ( action . method ) ;
334
344
var hasBody = action . method == 'POST' || action . method == 'PUT' || action . method == 'PATCH' ;
335
345
Resource [ name ] = function ( a1 , a2 , a3 , a4 ) {
336
346
var params = { } ;
@@ -396,11 +406,6 @@ angular.module('ngResource', ['ng']).
396
406
} ;
397
407
398
408
399
- Resource . bind = function ( additionalParamDefaults ) {
400
- return ResourceFactory ( url , extend ( { } , paramDefaults , additionalParamDefaults ) , actions ) ;
401
- } ;
402
-
403
-
404
409
Resource . prototype [ '$' + name ] = function ( a1 , a2 , a3 ) {
405
410
var params = extractParams ( this ) ,
406
411
success = noop ,
@@ -426,6 +431,11 @@ angular.module('ngResource', ['ng']).
426
431
Resource [ name ] . call ( this , params , data , success , error ) ;
427
432
} ;
428
433
} ) ;
434
+
435
+ Resource . bind = function ( additionalParamDefaults ) {
436
+ return ResourceFactory ( url , extend ( { } , paramDefaults , additionalParamDefaults ) , actions ) ;
437
+ } ;
438
+
429
439
return Resource ;
430
440
}
431
441
0 commit comments