Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3182: use unique attachment key to allow multiple image paste pe… #3821

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions notebook/static/notebook/js/textcell.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ define([
// We generate names for blobs
var key;
if (blob.name !== undefined) {
key = encodeURIandParens(blob.name);
key = utils.uuid() + '_' + encodeURIandParens(blob.name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should avoid UUIDs. They can be a problem when added to documents. Instead, collisions can be detected and avoided through a counter suffix.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't cells already have UUIDs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they don't. UUIDs are carefully avoided in the document format.

Looking now, there is a vestigial cell_id attribute in the code that shouldn't be present and isn't used for anything.

} else {
key = '_auto_' + Object.keys(that.attachments).length;
key = utils.uuid() +'_auto_' + Object.keys(that.attachments).length;
}

reader.onloadend = function() {
Expand Down
3 changes: 2 additions & 1 deletion notebook/tests/notebook/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ casper.notebook_test(function () {
var cell1 = this.evaluate(function() {
return Jupyter.notebook.get_cell(1);
});
this.test.assert('black_square_22.png' in cell0.attachments,
var cell0_att_filtered = Object.keys(cell0.attachments).filter(function(x) { return x.indexOf('black_square_22.png') >= 0} )
this.test.assert(cell0_att_filtered.length == 1,
'cell0 has kept its attachments');
this.test.assertEquals(Object.keys(cell1.attachments).length, 0,
'cell1 attachments have been garbage collected');
Expand Down