From 9e30baad3feafc82fb2f2011fd3f21909f4ba29e Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 16 Feb 2011 19:48:21 -0500 Subject: resources should not over-encode chars in url path - added encodeUriSegment that properly encodes only those chars that URI RFC requires us to encode - modified Resource to use encodeUriSegment --- src/Resource.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/Resource.js') diff --git a/src/Resource.js b/src/Resource.js index e801d200..f748fb5a 100644 --- a/src/Resource.js +++ b/src/Resource.js @@ -13,19 +13,20 @@ function Route(template, defaults) { Route.prototype = { url: function(params) { - var path = []; - var self = this; - var url = this.template; + var self = this, + url = this.template, + encodedVal; + params = params || {}; forEach(this.urlParams, function(_, urlParam){ - var value = params[urlParam] || self.defaults[urlParam] || ""; - url = url.replace(new RegExp(":" + urlParam + "(\\W)"), encodeURIComponent(value) + "$1"); + encodedVal = encodeUriSegment(params[urlParam] || self.defaults[urlParam] || "") + url = url.replace(new RegExp(":" + urlParam + "(\\W)"), encodedVal + "$1"); }); url = url.replace(/\/?#$/, ''); var query = []; forEachSorted(params, function(value, key){ if (!self.urlParams[key]) { - query.push(encodeURIComponent(key) + '=' + encodeURIComponent(value)); + query.push(encodeUriSegment(key) + '=' + encodeUriSegment(value)); } }); url = url.replace(/\/*$/, ''); -- cgit v1.2.3