decode language html correctly

main
Mike Fix 6 years ago
parent a16141bdfa
commit 0441205217

@ -32,7 +32,7 @@ import {
DEFAULT_LANGUAGE DEFAULT_LANGUAGE
} from '../lib/constants' } from '../lib/constants'
import { serializeState, getQueryStringState } from '../lib/routing' import { serializeState, getQueryStringState } from '../lib/routing'
import { getState, escapeHtml } from '../lib/util' import { getState, escapeHtml, unescapeHtml } from '../lib/util'
const saveButtonOptions = { const saveButtonOptions = {
button: true, button: true,
@ -89,13 +89,19 @@ class Editor extends React.Component {
console.log(e) console.log(e)
} }
// Load from localStorage and then URL params const newState = {
this.setState({ // Load from localStorage
...getState(localStorage), ...getState(localStorage),
// and then URL params
...initialState, ...initialState,
loading: false, loading: false,
online: Boolean(window && window.navigator && window.navigator.onLine) 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('offline', this.setOffline)
window.addEventListener('online', this.setOnline) 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 => { export const escapeHtml = s => {
if (typeof s === 'string') { if (typeof s === 'string') {
return s return s
.replace(/</g, '&lt;') .replace(/</g, '&lt;')
.replace(/>/g, '&gt;') .replace(/>/g, '&gt;')
.replace(/\//g, '&#x2F;') .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