From fcd369f21b05711490d42563f04dee9db9c21bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Bevacqua?= Date: Tue, 28 Jun 2016 17:46:50 -0300 Subject: [PATCH] [fix] Switch to attribute-encoding Former-commit-id: 2cdb0f9148ad14a0061376e989f1d2343dde93a5 --- src/ui/public/metadata.js | 8 +++----- src/ui/views/chrome.jade | 8 +------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/ui/public/metadata.js b/src/ui/public/metadata.js index 0b3897bb28e16..af93aeb616ed8 100644 --- a/src/ui/public/metadata.js +++ b/src/ui/public/metadata.js @@ -1,11 +1,9 @@ +import $ from 'jquery'; import _ from 'lodash'; -// singleton for immutable copy of window.__KBN__ -if (!_.has(window, '__KBN__')) { - throw new Error('window.__KBN__ must be set for metadata'); -} +const state = $('[kbn-initial-state]').attr('kbn-initial-state'); +const kbn = window.__KBN__ = JSON.parse(state); -const kbn = _.cloneDeep(window.__KBN__ || {}); export default deepFreeze(kbn); function deepFreeze(object) { diff --git a/src/ui/views/chrome.jade b/src/ui/views/chrome.jade index 357258de1b435..6091b440a54a4 100644 --- a/src/ui/views/chrome.jade +++ b/src/ui/views/chrome.jade @@ -1,12 +1,6 @@ - var appName = 'kibana'; - function encoded (data) { - var scriptend = /\<\s*\/\s*script\s*>/ig; - var concatend = ''; - return JSON.stringify(data).replace(scriptend, concatend); - } - block vars doctype html @@ -18,5 +12,5 @@ html(lang='en') title Kibana block head body(kbn-chrome, id='#{appName}-body') - script window.__KBN__ = !{encoded(kibanaPayload)}; + meta(kbn-initial-state=JSON.stringify(kibanaPayload)) block content