From b1371508ed514cb62466716bba6ec816c764801f Mon Sep 17 00:00:00 2001 From: Shihua Ma Date: Sat, 14 Jul 2018 06:33:20 +0800 Subject: [PATCH] fix base64 bug (#412) * fix base64 bug The Base64 table has Char '+' [https://en.wikipedia.org/wiki/Base64](https://en.wikipedia.org/wiki/Base64), it will turn to blank characters in url request, It will cause some error when deserializeState the state. * Fix encodeURIComponent for serialize --- lib/routing.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/routing.js b/lib/routing.js index 7492893..e71605c 100644 --- a/lib/routing.js +++ b/lib/routing.js @@ -50,11 +50,13 @@ const reverseMappings = mappings.map(mapping => ) export const serializeState = state => { - const stateString = encodeURIComponent(JSON.stringify(state)) + const stateString = JSON.stringify(state) - return typeof window !== 'undefined' - ? btoa(stateString) - : Buffer.from(stateString).toString('base64') + return encodeURIComponent( + typeof window !== 'undefined' + ? btoa(stateString) + : Buffer.from(stateString).toString('base64') + ) } export const deserializeState = serializedState => {