Skip to content

Commit 4a8b756

Browse files
mhilsryanflorence
authored andcommitted
[fixed] empty query strings not being removed
Conflicts: package.json
1 parent 51f6f72 commit 4a8b756

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

modules/PathUtils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var invariant = require('react/lib/invariant');
2-
var merge = require('qs/lib/utils').merge;
2+
var objectAssign = require('object-assign');
33
var qs = require('qs');
44

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

146146
if (existingQuery)
147-
query = query ? merge(existingQuery, query) : existingQuery;
147+
query = query ? objectAssign(existingQuery, query) : existingQuery;
148148

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

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

154-
return path;
154+
return Path.withoutQuery(path);
155155
}
156156

157157
};

modules/__tests__/PathUtils-test.js

+4
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ describe('PathUtils.withQuery', function () {
319319
expect(PathUtils.withQuery('/path?a=b', { c: [ 'd', 'e' ] })).toEqual('/path?a=b&c%5B%5D=d&c%5B%5D=e');
320320
});
321321

322+
it('removes query string', function () {
323+
expect(Path.withQuery('/a/b/c?a=b', { a: undefined })).toEqual('/a/b/c');
324+
});
325+
322326
it('handles special characters', function () {
323327
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');
324328
});

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
},
4848
"dependencies": {
4949
"qs": "2.4.1",
50-
"classnames": "1.1.x"
50+
"classnames": "1.1.x",
51+
"object-assign": "^2.0.0"
5152
},
5253
"tags": [
5354
"react",

0 commit comments

Comments
 (0)