Skip to content

Commit

Permalink
Merge pull request #7584 from elastic/jasper/backport/7578/5.0.0-alpha4
Browse files Browse the repository at this point in the history
[5.0.0-alpha4] Fixed scripting issues due to improperly encoded kibana payload
  • Loading branch information
epixa authored Jun 29, 2016
2 parents 808ee90 + 422f570 commit c22c5da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions src/ui/public/metadata.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
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 kbn = _.cloneDeep(window.__KBN__ || {});
export default deepFreeze(kbn);
export default deepFreeze(getState());

function deepFreeze(object) {
// for any properties that reference an object, makes sure that object is
Expand All @@ -20,3 +15,12 @@ function deepFreeze(object) {

return Object.freeze(object);
}

function getState() {
const stateKey = '__KBN__';
if (!(stateKey in window)) {
const state = $('kbn-initial-state').attr('data');
window[stateKey] = JSON.parse(state);
}
return window[stateKey];
}
6 changes: 3 additions & 3 deletions src/ui/views/chrome.jade
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- var j = function (o) { return JSON.stringify(o); }
- var appName = 'kibana';
-
var appName = 'kibana';
block vars

Expand All @@ -12,5 +12,5 @@ html(lang='en')
title Kibana
block head
body(kbn-chrome, id='#{appName}-body')
script window.__KBN__ = !{j(kibanaPayload)};
kbn-initial-state(data=JSON.stringify(kibanaPayload))
block content

0 comments on commit c22c5da

Please sign in to comment.