Skip to content

Commit

Permalink
Merge pull request #14 from alexvarney/special-url-chars
Browse files Browse the repository at this point in the history
Handle special url chars
  • Loading branch information
anzorb authored Dec 2, 2020
2 parents 1e4fea2 + 70bb8d3 commit d65b8a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions packages/url-persistence/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ describe('with URL persistence', () => {
expect(window.location.hash).toBe('#/work?activity=daydreaming');
});

it('should update query params with special chars', () => {
stateMachineRouter.emit(ACTION.goToWork);
stateMachineRouter.emit(ACTION.slack, { activity: '%+-/!@#$^&*() text' });
expect(window.location.hash).toBe(
'#/work?activity=%25%2B-%2F!%40%23%24%5E%26*()%20text'
);
});

it('should read state from query params with special chars', async () => {
window.location.hash =
'/work?activity=%25%2B-%2F!%40%23%24%5E%26*()%20text';
await ms(10);
expect(stateMachineRouter.currentState.params.activity).toBe(
'%+-/!@#$^&*() text'
);
});

it('should nullify query params', () => {
stateMachineRouter.emit(ACTION.goToWork);
stateMachineRouter.emit(ACTION.slack, { activity: null });
Expand Down
4 changes: 2 additions & 2 deletions packages/url-persistence/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const deserialize = (params, serializers: ISerializers | undefined): object => {
throw new Error(err);
}
} else {
paramsObject[key] = decodeURI(params[key]);
paramsObject[key] = params[key]
}
});
return paramsObject;
Expand All @@ -52,7 +52,7 @@ const serialize = (params, serializers: ISerializers | undefined): string => {
throw new Error(err);
}
} else {
paramsString += `${key}=${encodeURI(params[key])}&`;
paramsString += `${key}=${encodeURIComponent(params[key])}&`;
}
});

Expand Down

0 comments on commit d65b8a3

Please sign in to comment.