Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding URI#removeParam method to support some cleanup in JSONP calls,…

… and moving decode calls out of URI#setParam() into URI.parse() to avoid unintentional decoding.
  • Loading branch information...
commit fb46650ff8b09423a25c9f381f3da7faac3b297e 1 parent 28cae3b
@jcoglan jcoglan authored beastaugh committed
View
2  source/packages/http/cross_domain.js
@@ -122,7 +122,7 @@
if (uri.params.jsonp && callbacks.onSuccess) {
var handlerID = getHandlerId();
uri.setParam(uri.params.jsonp, handlerID);
- if (uri.params.jsonp !== 'jsonp') delete uri.params.jsonp;
+ if (uri.params.jsonp !== 'jsonp') uri.removeParam('jsonp');
window[handlerID] = handleJsonP.partial(callbacks.onSuccess, handlerID);
callbacks.onSuccess = null;
}
View
14 source/packages/http/uri.js
@@ -36,7 +36,8 @@ Ojay.URI = new JS.Class('Ojay.URI', {
if (/^\?/.test(string)) string.slice(1).split('&').forEach(function(pair) {
var bits = pair.split('=');
- uri.setParam(bits[0], bits[1].replace('+', ' '));
+ uri.setParam(decodeURIComponent(bits[0]),
+ decodeURIComponent(bits[1].replace('+', ' ')));
});
return uri;
},
@@ -137,12 +138,21 @@ Ojay.URI = new JS.Class('Ojay.URI', {
* @param {String} value
*/
setParam: function(key, value) {
- var bits = [key, value].map(decodeURIComponent).map('trim');
+ var bits = [key, value].map('trim');
if (this.keys.indexOf(bits[0]) == -1) this.keys.push(bits[0]);
this.params[bits[0]] = bits[1];
},
/**
+ * @param {String} key
+ */
+ removeParam: function(key) {
+ delete this.params[key];
+ var index = this.keys.indexOf(key);
+ if (index > -1) this.keys.splice(index, 1);
+ },
+
+ /**
* @param {String|URI} uri
* @returns {Boolean}
*/
Please sign in to comment.
Something went wrong with that request. Please try again.