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
main
Shihua Ma 6 years ago committed by Michael Fix
parent 0525a9fcca
commit b1371508ed

@ -50,11 +50,13 @@ const reverseMappings = mappings.map(mapping =>
) )
export const serializeState = state => { export const serializeState = state => {
const stateString = encodeURIComponent(JSON.stringify(state)) const stateString = JSON.stringify(state)
return typeof window !== 'undefined' return encodeURIComponent(
typeof window !== 'undefined'
? btoa(stateString) ? btoa(stateString)
: Buffer.from(stateString).toString('base64') : Buffer.from(stateString).toString('base64')
)
} }
export const deserializeState = serializedState => { export const deserializeState = serializedState => {

Loading…
Cancel
Save