Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Fix: support Unicode in URL hash (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea authored and ilyavolodin committed Oct 16, 2017
1 parent 40a9885 commit 1e75d9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions js/app/demo/app.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

define(["react", "jsx!editor", "jsx!messages", "jsx!fixedCode", "jsx!configuration", "eslint"], function(React, Editor, Messages, FixedCode, Configuration, Linter) {
define(["react", "jsx!editor", "jsx!messages", "jsx!fixedCode", "jsx!configuration", "eslint", "unicode"], function(React, Editor, Messages, FixedCode, Configuration, Linter, Unicode) {
var hasLocalStorage = (function() {
try {
window.localStorage.setItem("localStorageTest", "foo");
Expand Down Expand Up @@ -58,7 +58,7 @@ define(["react", "jsx!editor", "jsx!messages", "jsx!fixedCode", "jsx!configurati
var storedState = JSON.parse(window.localStorage.getItem("linterDemoState") || null);
var urlState = (function() {
try {
return JSON.parse(window.atob(window.location.hash.replace(/^#/, "")));
return JSON.parse(Unicode.decodeFromBase64(window.location.hash.replace(/^#/, "")));
} catch (err) {
return null;
}
Expand Down Expand Up @@ -108,7 +108,7 @@ define(["react", "jsx!editor", "jsx!messages", "jsx!fixedCode", "jsx!configurati
if (hasLocalStorage) {
window.localStorage.setItem("linterDemoState", serializedState);
}
window.location.hash = window.btoa(serializedState);
window.location.hash = Unicode.encodeToBase64(serializedState);
},
enableFixMode: function() {
this.setState({ fix: true });
Expand Down
16 changes: 16 additions & 0 deletions js/app/demo/unicode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";

define([], function() {

// Provides conversion functions between a unicode string and a base64 string.
// See also: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/btoa#Unicode_strings
return {
encodeToBase64: function(text) {
return window.btoa(unescape(encodeURIComponent(text)));
},

decodeFromBase64: function(base64) {
return decodeURIComponent(escape(window.atob(base64)));
}
};
});

0 comments on commit 1e75d9e

Please sign in to comment.