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.
This commit is contained in:
MinRK 2013-11-20 12:50:40 -08:00
parent 2d871ff682
commit d6deaaaf1f

View File

@ -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;
};