From 85bfc25bec77ab00204673783b11fafaaf682477 Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Mon, 18 Apr 2016 19:17:06 +0200 Subject: [PATCH 1/2] Fixes nodes w/ a slash under a path-prefixed scope. E.g. localhost:4043/scoped/{state:{label:"/zing"... Double encode is solution! - https://github.com/visionmedia/page.js/issues/187 --- client/app/scripts/utils/router-utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/app/scripts/utils/router-utils.js b/client/app/scripts/utils/router-utils.js index df39d11d82..8bcddf7b13 100644 --- a/client/app/scripts/utils/router-utils.js +++ b/client/app/scripts/utils/router-utils.js @@ -14,12 +14,12 @@ function shouldReplaceState(prevState, nextState) { export function updateRoute() { const state = AppStore.getAppState(); - const stateUrl = JSON.stringify(state); + const stateUrl = encodeURIComponent(encodeURIComponent(JSON.stringify(state))); const dispatch = false; const urlStateString = window.location.hash .replace('#!/state/', '') .replace('#!/', '') || '{}'; - const prevState = JSON.parse(decodeURIComponent(urlStateString)); + const prevState = JSON.parse(decodeURIComponent(decodeURIComponent(urlStateString))); if (shouldReplaceState(prevState, state)) { // Replace the top of the history rather than pushing on a new item. From eb86473a4a6d105b7bf69ed8c17a8d1355ebd4de Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Mon, 18 Apr 2016 19:41:14 +0200 Subject: [PATCH 2/2] Make state urls pretty again. Use a magical constant instead of double encoding --- client/app/scripts/utils/router-utils.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/app/scripts/utils/router-utils.js b/client/app/scripts/utils/router-utils.js index 8bcddf7b13..15d70c1c4d 100644 --- a/client/app/scripts/utils/router-utils.js +++ b/client/app/scripts/utils/router-utils.js @@ -3,6 +3,12 @@ import page from 'page'; import { route } from '../actions/app-actions'; import AppStore from '../stores/app-store'; +// +// page.js won't match the routes below if ":state" has a slash in it, so replace those before we +// load the state into the URL. +// +const SLASH_REPLACEMENT = ''; + function shouldReplaceState(prevState, nextState) { // Opening a new terminal while an existing one is open. const terminalToTerminal = (prevState.controlPipe && nextState.controlPipe); @@ -14,12 +20,12 @@ function shouldReplaceState(prevState, nextState) { export function updateRoute() { const state = AppStore.getAppState(); - const stateUrl = encodeURIComponent(encodeURIComponent(JSON.stringify(state))); + const stateUrl = JSON.stringify(state).replace('/', SLASH_REPLACEMENT); const dispatch = false; const urlStateString = window.location.hash .replace('#!/state/', '') .replace('#!/', '') || '{}'; - const prevState = JSON.parse(decodeURIComponent(decodeURIComponent(urlStateString))); + const prevState = JSON.parse(decodeURIComponent(urlStateString.replace(SLASH_REPLACEMENT, '/'))); if (shouldReplaceState(prevState, state)) { // Replace the top of the history rather than pushing on a new item.