actually fix decoding errors bugs

main
Mike Fix 6 years ago
parent 9acda4024f
commit 4a87519409

@ -80,6 +80,7 @@ export const getQueryStringState = query => {
}
const state = mapper.map(mappings, query)
deserializeCode(state)
Object.keys(state).forEach(key => {
if (state[key] === '') state[key] = undefined
@ -91,10 +92,27 @@ export const getQueryStringState = query => {
export const updateQueryString = state => {
if (history.location.search.indexOf('react_perf') < 0) {
const mappedState = mapper.map(reverseMappings, state)
serializeCode(mappedState)
history.replace({
// Do NOT change this to encodeURIComponent
search: encodeURI(keysToQuery(mappedState))
})
}
}
// private
function serializeCode(state) {
try {
if (state.code) state.code = encodeURIComponent(state.code)
} catch (e) {
// encoding errors should not crash the app
}
}
function deserializeCode(state) {
try {
if (state.code) state.code = decodeURIComponent(state.code)
} catch (e) {
// decoding errors should not crash the app
}
}

Loading…
Cancel
Save