mirror of
https://github.com/jupyter/notebook.git
synced 2024-11-27 03:20:27 +08:00
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:
parent
2d871ff682
commit
d6deaaaf1f
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user