Skip to content
This repository was archived by the owner on May 8, 2023. It is now read-only.

Commit 4b84554

Browse files
MikaFimaovidiuch
authored andcommitted
Parse form spaces on routed query string (#7)
1 parent 14e1a25 commit 4b84554

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/react-querystring-router/src/__tests__/uri.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,15 @@ test('generates location with query string from params', () => {
3636

3737
expect(stringifyParams(params)).toBe('?name=Jack&info=%7B%22age%22%3A25%7D');
3838
});
39+
40+
test('parses stringified and form encoded params from location', () => {
41+
const uriLocation =
42+
'mypage.com?formValue=first+middle+last&encodedValue=first%20middle%20last&plusValue=first%2Bmiddle%2Blast';
43+
const params = parseLocation(uriLocation);
44+
45+
expect(params).toEqual({
46+
formValue: 'first middle last',
47+
encodedValue: 'first middle last',
48+
plusValue: 'first+middle+last'
49+
});
50+
});

packages/react-querystring-router/src/uri.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function parseLocation(location) {
1818
pairs.forEach(pair => {
1919
parts = pair.split('=');
2020
[key] = parts;
21-
value = decodeURIComponent(parts[1]);
21+
value = decodeURIComponent(parts[1].replace(/\+/g, '%20'));
2222

2323
try {
2424
value = JSON.parse(value);

0 commit comments

Comments
 (0)