Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 0cecde8

Browse files
committed
refactor(ngResource): Use core encode methods in ngResource
Core package and ngResource both defined methods for encodeUriQuery and encodeUriSegment. ngResource's methods are out of date. Use core encode methods in ngResource
1 parent e34ef23 commit 0cecde8

File tree

2 files changed

+5
-42
lines changed

2 files changed

+5
-42
lines changed

src/AngularPublic.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ function publishExternalAPI(angular) {
152152
'getTestability': getTestability,
153153
'$$minErr': minErr,
154154
'$$csp': csp,
155-
'reloadWithDebugInfo': reloadWithDebugInfo
155+
'reloadWithDebugInfo': reloadWithDebugInfo,
156+
'encodeUriSegment': encodeUriSegment,
157+
'encodeUriQuery': encodeUriQuery
156158
});
157159

158160
angularModule = setupModuleLoader(window);

src/ngResource/resource.js

+2-41
Original file line numberDiff line numberDiff line change
@@ -424,45 +424,6 @@ angular.module('ngResource', ['ng']).
424424
copy = angular.copy,
425425
isFunction = angular.isFunction;
426426

427-
/**
428-
* We need our custom method because encodeURIComponent is too aggressive and doesn't follow
429-
* http://www.ietf.org/rfc/rfc3986.txt with regards to the character set
430-
* (pchar) allowed in path segments:
431-
* segment = *pchar
432-
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
433-
* pct-encoded = "%" HEXDIG HEXDIG
434-
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
435-
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
436-
* / "*" / "+" / "," / ";" / "="
437-
*/
438-
function encodeUriSegment(val) {
439-
return encodeUriQuery(val, true).
440-
replace(/%26/gi, '&').
441-
replace(/%3D/gi, '=').
442-
replace(/%2B/gi, '+');
443-
}
444-
445-
446-
/**
447-
* This method is intended for encoding *key* or *value* parts of query component. We need a
448-
* custom method because encodeURIComponent is too aggressive and encodes stuff that doesn't
449-
* have to be encoded per http://tools.ietf.org/html/rfc3986:
450-
* query = *( pchar / "/" / "?" )
451-
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
452-
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
453-
* pct-encoded = "%" HEXDIG HEXDIG
454-
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
455-
* / "*" / "+" / "," / ";" / "="
456-
*/
457-
function encodeUriQuery(val, pctEncodeSpaces) {
458-
return encodeURIComponent(val).
459-
replace(/%40/gi, '@').
460-
replace(/%3A/gi, ':').
461-
replace(/%24/g, '$').
462-
replace(/%2C/gi, ',').
463-
replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
464-
}
465-
466427
function Route(template, defaults) {
467428
this.template = template;
468429
this.defaults = extend({}, provider.defaults, defaults);
@@ -500,9 +461,9 @@ angular.module('ngResource', ['ng']).
500461
val = params.hasOwnProperty(urlParam) ? params[urlParam] : self.defaults[urlParam];
501462
if (angular.isDefined(val) && val !== null) {
502463
if (paramInfo.isQueryParamValue) {
503-
encodedVal = encodeUriQuery(val, true);
464+
encodedVal = angular.encodeUriQuery(val, true);
504465
} else {
505-
encodedVal = encodeUriSegment(val);
466+
encodedVal = angular.encodeUriSegment(val);
506467
}
507468
url = url.replace(new RegExp(":" + urlParam + "(\\W|$)", "g"), function(match, p1) {
508469
return encodedVal + p1;

0 commit comments

Comments
 (0)