11/**
2- * @license AngularJS v1.0.3
2+ * @license AngularJS v1.0.4
33 * (c) 2010-2012 Google, Inc. http://angularjs.org
44 * License: MIT
55 */
1212 * @description
1313 */
1414
15- /**
15+ /**
1616 * @ngdoc object
1717 * @name ngResource.$resource
1818 * @requires $http
2525 * the need to interact with the low level {@link ng.$http $http} service.
2626 *
2727 * @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')`.
2931 *
3032 * @param {Object= } paramDefaults Default values for `url` parameters. These can be overridden in
3133 * `actions` methods.
@@ -230,46 +232,46 @@ angular.module('ngResource', ['ng']).
230232 return $parse ( path ) ( obj ) ;
231233 } ;
232234
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 ) {
273275 this . template = template = template + '#' ;
274276 this . defaults = defaults || { } ;
275277 var urlParams = this . urlParams = { } ;
@@ -295,7 +297,14 @@ angular.module('ngResource', ['ng']).
295297 encodedVal = encodeUriSegment ( val ) ;
296298 url = url . replace ( new RegExp ( ":" + urlParam + "(\\W)" , "g" ) , encodedVal + "$1" ) ;
297299 } 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+ } ) ;
299308 }
300309 } ) ;
301310 url = url . replace ( / \/ ? # $ / , '' ) ;
@@ -331,6 +340,7 @@ angular.module('ngResource', ['ng']).
331340 }
332341
333342 forEach ( actions , function ( action , name ) {
343+ action . method = angular . uppercase ( action . method ) ;
334344 var hasBody = action . method == 'POST' || action . method == 'PUT' || action . method == 'PATCH' ;
335345 Resource [ name ] = function ( a1 , a2 , a3 , a4 ) {
336346 var params = { } ;
@@ -396,11 +406,6 @@ angular.module('ngResource', ['ng']).
396406 } ;
397407
398408
399- Resource . bind = function ( additionalParamDefaults ) {
400- return ResourceFactory ( url , extend ( { } , paramDefaults , additionalParamDefaults ) , actions ) ;
401- } ;
402-
403-
404409 Resource . prototype [ '$' + name ] = function ( a1 , a2 , a3 ) {
405410 var params = extractParams ( this ) ,
406411 success = noop ,
@@ -426,6 +431,11 @@ angular.module('ngResource', ['ng']).
426431 Resource [ name ] . call ( this , params , data , success , error ) ;
427432 } ;
428433 } ) ;
434+
435+ Resource . bind = function ( additionalParamDefaults ) {
436+ return ResourceFactory ( url , extend ( { } , paramDefaults , additionalParamDefaults ) , actions ) ;
437+ } ;
438+
429439 return Resource ;
430440 }
431441
0 commit comments