From 75f1b9ae2634056f23779cc2321f78e845a79c0c Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Wed, 26 Jul 2017 13:55:19 +0100 Subject: [PATCH 1/2] Don't assume that application/ mime types are editable The application media type includes many common binary files like application/zip and application/pdf. --- notebook/static/tree/js/notebooklist.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 16284582b..c5c1b819f 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -545,7 +545,7 @@ define([ }; NotebookList.prototype._is_editable = function(model) { - return (includes_mimetype('text/', model.mimetype) || includes_mimetype('application/', model.mimetype)) + return includes_mimetype('text/', model.mimetype) || includes_extension(model.path, NotebookList.editable_extensions); }; From 5c66955fabd22683b0d2280311c566cbd0e44e4e Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Wed, 26 Jul 2017 14:38:44 +0100 Subject: [PATCH 2/2] Smarter check for editable mimetypes --- notebook/static/tree/js/notebooklist.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index c5c1b819f..562ef1fe8 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -30,9 +30,11 @@ define([ var includes_extension = function(filepath, extensionslist) { return item_in(extension(filepath), extensionslist); }; - - var includes_mimetype = function(str, mimetype) { - return item_in(str, mimetype || ''); + + var json_or_xml_container_mimetype = function(mimetype) { + // Match */*+json or */*+xml + return (mimetype.substring(mimetype.length - 5) == '+json' + || mimetype.substring(mimetype.length - 4) == '+xml'); }; function name_sorter(ascending) { @@ -545,7 +547,12 @@ define([ }; NotebookList.prototype._is_editable = function(model) { - return includes_mimetype('text/', model.mimetype) + // Editable: any text/ mimetype, specific mimetypes defined as editable, + // +json and +xml mimetypes, specific extensions listed as editable. + return model.mimetype && + (model.mimetype.indexOf('text/') === 0 + || item_in(model.mimetype, this.EDIT_MIMETYPES) + || json_or_xml_container_mimetype(model.mimetype)) || includes_extension(model.path, NotebookList.editable_extensions); };