aboutsummaryrefslogtreecommitdiffstats
path: root/src/Angular.js
diff options
context:
space:
mode:
authorIgor Minar2011-03-31 21:45:28 -0700
committerIgor Minar2011-03-31 21:45:28 -0700
commit78a0f41058a3c8094cf3b8979baa212a3b88b2a6 (patch)
tree65ea56de5dc593a7897c36ede315960db5d129fb /src/Angular.js
parenteccd9bfbb3d63731814941789089e1c799005fb4 (diff)
downloadangular.js-78a0f41058a3c8094cf3b8979baa212a3b88b2a6.tar.bz2
encode query params correctly but not too agressively
Diffstat (limited to 'src/Angular.js')
-rw-r--r--src/Angular.js36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 9a607ba3..e297905a 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -811,20 +811,44 @@ function toKeyValue(obj) {
/**
* we need our custom mehtod because encodeURIComponent is too agressive and doesn't follow
- * http://www.ietf.org/rfc/rfc2396.txt with regards to the character set (pchar) allowed in path
- * segments
+ * http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
+ * segments:
+ * segment = *pchar
+ * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
+ * pct-encoded = "%" HEXDIG HEXDIG
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
+ * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
+ * / "*" / "+" / "," / ";" / "="
*/
function encodeUriSegment(val) {
+ return encodeUriQuery(val, true).
+ replace(/%26/gi, '&').
+ replace(/%3D/gi, '=').
+ replace(/%2B/gi, '+');
+}
+
+
+/**
+ * This method is intended for encoding *key* or *value* parts of query component. We need a custom
+ * method becuase encodeURIComponent is too agressive and encodes stuff that doesn't have to be
+ * encoded per http://tools.ietf.org/html/rfc3986:
+ * query = *( pchar / "/" / "?" )
+ * pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
+ * pct-encoded = "%" HEXDIG HEXDIG
+ * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
+ * / "*" / "+" / "," / ";" / "="
+ */
+function encodeUriQuery(val, pctEncodeSpaces) {
return encodeURIComponent(val).
replace(/%40/gi, '@').
replace(/%3A/gi, ':').
- replace(/%26/gi, '&').
- replace(/%3D/gi, '=').
- replace(/%2B/gi, '+').
replace(/%24/g, '$').
- replace(/%2C/gi, ',');
+ replace(/%2C/gi, ',').
+ replace((pctEncodeSpaces ? null : /%20/g), '+');
}
+
/**
* @workInProgress
* @ngdoc directive