Skip to content

Commit

Permalink
[fixed] empty query strings not being removed
Browse files Browse the repository at this point in the history
Conflicts:
	package.json
  • Loading branch information
mhils authored and ryanflorence committed Mar 21, 2015
1 parent 51f6f72 commit 4a8b756
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions modules/PathUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var invariant = require('react/lib/invariant');
var merge = require('qs/lib/utils').merge;
var objectAssign = require('object-assign');
var qs = require('qs');

var paramCompileMatcher = /:([a-zA-Z_$][a-zA-Z0-9_$]*)|[*.()\[\]\\+|{}^$]/g;
Expand Down Expand Up @@ -144,14 +144,14 @@ var PathUtils = {
var existingQuery = PathUtils.extractQuery(path);

if (existingQuery)
query = query ? merge(existingQuery, query) : existingQuery;
query = query ? objectAssign(existingQuery, query) : existingQuery;

var queryString = qs.stringify(query, { arrayFormat: 'brackets' });

if (queryString)
return PathUtils.withoutQuery(path) + '?' + queryString;

return path;
return Path.withoutQuery(path);
}

};
Expand Down
4 changes: 4 additions & 0 deletions modules/__tests__/PathUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ describe('PathUtils.withQuery', function () {
expect(PathUtils.withQuery('/path?a=b', { c: [ 'd', 'e' ] })).toEqual('/path?a=b&c%5B%5D=d&c%5B%5D=e');
});

it('removes query string', function () {
expect(Path.withQuery('/a/b/c?a=b', { a: undefined })).toEqual('/a/b/c');
});

it('handles special characters', function () {
expect(PathUtils.withQuery('/path?a=b', { c: [ 'd#e', 'f&a=i#j+k' ] })).toEqual('/path?a=b&c%5B%5D=d%23e&c%5B%5D=f%26a%3Di%23j%2Bk');
});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
},
"dependencies": {
"qs": "2.4.1",
"classnames": "1.1.x"
"classnames": "1.1.x",
"object-assign": "^2.0.0"
},
"tags": [
"react",
Expand Down

0 comments on commit 4a8b756

Please sign in to comment.