From 46091f6dc5c012ddf0a8f74b5ea14124d348d934 Mon Sep 17 00:00:00 2001 From: briandennis Date: Mon, 12 Feb 2018 15:57:23 -0600 Subject: [PATCH] URI component encode carbon text --- lib/routing.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/routing.js b/lib/routing.js index 3dc8f9b..0bc00e9 100644 --- a/lib/routing.js +++ b/lib/routing.js @@ -46,6 +46,7 @@ const keysToQuery = keys => export const getQueryStringState = query => { const state = mapper.map(mappings, query) + deserializeCode(state) Object.keys(state).forEach(key => { if (state[key] === '') state[key] = undefined @@ -54,7 +55,20 @@ export const getQueryStringState = query => { return state } -export const updateQueryString = state => +export const updateQueryString = state => { + let mappedState = mapper.map(reverseMappings, state) + serializeCode(mappedState) + history.replace({ - search: encodeURI(keysToQuery(mapper.map(reverseMappings, state))) + search: encodeURI(keysToQuery(mappedState)) }) +} + +// private +function serializeCode(state) { + if (state.code) state.code = encodeURIComponent(state.code) +} + +function deserializeCode(state) { + if (state.code) state.code = decodeURIComponent(state.code) +}