From 570aeb480f33253bb4c5ca1970f47dba25c9768b 2014-01-12 22:24:16 From: MinRK Date: 2014-01-12 22:24:16 Subject: [PATCH] protect javascript from invalid mime-type data everything is a string, if anything else is sent, drop it so it doesn't show up in the notebook document. --- diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js index 45ee860..a284cc7 100644 --- a/IPython/html/static/notebook/js/outputarea.js +++ b/IPython/html/static/notebook/js/outputarea.js @@ -277,11 +277,26 @@ var IPython = (function (IPython) { "javascript" : "application/javascript", }; + OutputArea.prototype._safe_set_mime = function (src, dest, srckey, destkey) { + destkey = destkey || srckey; + + var value = src[srckey]; + if (value !== undefined) { + // For now, everything is a string, + // but JSON should really not be double-serialized. + if (typeof value !== 'string') { + console.log("Invalid type for " + destkey, value); + } else { + dest[destkey] = value; + } + } + }; + OutputArea.prototype.rename_keys = function (data, key_map) { var remapped = {}; for (var key in data) { var new_key = key_map[key] || key; - remapped[new_key] = data[key]; + this._safe_set_mime(data, remapped, key, new_key); } return remapped; };