Skip to content

Commit

Permalink
Changed the url.remove function to be case-insensitive.
Browse files Browse the repository at this point in the history
  • Loading branch information
jordandh committed Oct 6, 2015
1 parent 41e5f7e commit 7e924a6
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,29 @@ define(['sprout/util', 'sprout/purl'], function (_, purl) {
};

/**
* Removes the querystirng parameters passed in.
* Removes the querystirng parameters passed in. Case-insensitive
* @param {String} params A space delimited string of querystring parameters to removed from the url.
* @return {url} This url object is returned for chaining.
*/
url.remove = function (params) {
var keysToRemove = [];

// Loop through each param to remove
_.each(params.split(' '), function (param) {
delete this.data.param.query[param];
param = param.toLowerCase();

// Loop through each existing param to do a case-insensitive comparison
_.each(this.data.param.query, function (value, key) {
// If the param keys are the same then store this key to be removed after the looping
if (param === key.toLowerCase()) {
keysToRemove.push(key);
}
});
}, this);

// Remove the keys that matched
this.data.param.query = _.omit(this.data.param.query, keysToRemove);

return this;
};

Expand Down

0 comments on commit 7e924a6

Please sign in to comment.