mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 01:31:17 +00:00
Merge pull request #1346 from weaveworks/1335-nodes-with-a-slash
Change url encoding to handle multiple slashes in node names
This commit is contained in:
@@ -7,8 +7,17 @@ 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 = '/';
|
||||
const SLASH_REPLACEMENT = '<SLASH>';
|
||||
|
||||
function encodeURL(url) {
|
||||
return url.replace(new RegExp(SLASH, 'g'), SLASH_REPLACEMENT);
|
||||
}
|
||||
|
||||
function decodeURL(url) {
|
||||
return decodeURIComponent(url.replace(new RegExp(SLASH_REPLACEMENT, 'g'), SLASH));
|
||||
}
|
||||
|
||||
function shouldReplaceState(prevState, nextState) {
|
||||
// Opening a new terminal while an existing one is open.
|
||||
const terminalToTerminal = (prevState.controlPipe && nextState.controlPipe);
|
||||
@@ -20,12 +29,12 @@ function shouldReplaceState(prevState, nextState) {
|
||||
|
||||
export function updateRoute() {
|
||||
const state = AppStore.getAppState();
|
||||
const stateUrl = JSON.stringify(state).replace('/', SLASH_REPLACEMENT);
|
||||
const stateUrl = encodeURL(JSON.stringify(state));
|
||||
const dispatch = false;
|
||||
const urlStateString = window.location.hash
|
||||
.replace('#!/state/', '')
|
||||
.replace('#!/', '') || '{}';
|
||||
const prevState = JSON.parse(decodeURIComponent(urlStateString.replace(SLASH_REPLACEMENT, '/')));
|
||||
const prevState = JSON.parse(decodeURL(urlStateString));
|
||||
|
||||
if (shouldReplaceState(prevState, state)) {
|
||||
// Replace the top of the history rather than pushing on a new item.
|
||||
|
||||
Reference in New Issue
Block a user