decode language html correctly

main
Mike Fix 6 years ago
parent a16141bdfa
commit 0441205217

@ -32,7 +32,7 @@ import {
DEFAULT_LANGUAGE
} from '../lib/constants'
import { serializeState, getQueryStringState } from '../lib/routing'
import { getState, escapeHtml } from '../lib/util'
import { getState, escapeHtml, unescapeHtml } from '../lib/util'
const saveButtonOptions = {
button: true,
@ -89,13 +89,19 @@ class Editor extends React.Component {
console.log(e)
}
// Load from localStorage and then URL params
this.setState({
const newState = {
// Load from localStorage
...getState(localStorage),
// and then URL params
...initialState,
loading: false,
online: Boolean(window && window.navigator && window.navigator.onLine)
})
}
// Makes sure the slash in encoded in application/X is decoded
newState.language = unescapeHtml(newState.language)
this.setState(newState)
window.addEventListener('offline', this.setOffline)
window.addEventListener('online', this.setOnline)

@ -12,12 +12,25 @@ const parse = v => {
}
}
// https://gist.github.com/alexgibson/1704515
// TODO use https://github.com/sindresorhus/escape-goat/
export const escapeHtml = s => {
if (typeof s === 'string') {
return s
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\//g, '&#x2F;')
.replace(/&/g, '&amp;')
}
}
export const unescapeHtml = s => {
if (typeof s === 'string') {
return s
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&#x2F;/g, '/')
.replace(/&amp;/g, '&');
}
}

Loading…
Cancel
Save