Skip to content

Commit

Permalink
URL encode data before making URL
Browse files Browse the repository at this point in the history
  • Loading branch information
joefiorini committed Jan 10, 2015
1 parent a702d1b commit 0a5619b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 9 additions & 2 deletions build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@

if (matches && matches.length && matches.length > 0) {
var serializedState = matches[1];
var deserializedState = JSON.parse(atob(serializedState));
var decodedState = decodeURIComponent(serializedState);
var deserializedState = JSON.parse(atob(decodedState));
var adaptedState = adapt(deserializedState);
console.log(adaptedState);
board.ports.loadedState.send(adaptedState);
Expand All @@ -90,11 +91,17 @@
}, 50);
});

function urlForState(state) {
var encoded = encodeURIComponent(state);
return window.location.protocol + "//" + window.location.host + "/boards/" + encoded
}

board.ports.serializeState.subscribe(function(state) {
var encoded = btoa(JSON.stringify(state));
var input = document.querySelector(".share__url");
var url = urlForState(encoded);

input.value = window.location.protocol + "//" + window.location.host + "/boards/" + encoded;
input.value = url;
input.select();
return state;
});
Expand Down
11 changes: 9 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@

if (matches && matches.length && matches.length > 0) {
var serializedState = matches[1];
var deserializedState = JSON.parse(atob(serializedState));
var decodedState = decodeURIComponent(serializedState);
var deserializedState = JSON.parse(atob(decodedState));
var adaptedState = adapt(deserializedState);
console.log(adaptedState);
board.ports.loadedState.send(adaptedState);
Expand All @@ -90,11 +91,17 @@
}, 50);
});

function urlForState(state) {
var encoded = encodeURIComponent(state);
return window.location.protocol + "//" + window.location.host + "/boards/" + encoded
}

board.ports.serializeState.subscribe(function(state) {
var encoded = btoa(JSON.stringify(state));
var input = document.querySelector(".share__url");
var url = urlForState(encoded);

input.value = window.location.protocol + "//" + window.location.host + "/boards/" + encoded;
input.value = url;
input.select();
return state;
});
Expand Down

0 comments on commit 0a5619b

Please sign in to comment.