Skip to content

Commit

Permalink
fix(dia.Cell): prevent exception when removeProp() called on non-exis…
Browse files Browse the repository at this point in the history
…ting top-level attribute (#1898)
  • Loading branch information
kumilingus authored Nov 18, 2022
1 parent 9cdc6a1 commit f983f8d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/dia/Cell.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,9 @@ export const Cell = Backbone.Model.extend({

// A nested property
var nestedPath = pathArray.slice(1);
var propertyValue = cloneDeep(this.get(property));
var propertyValue = this.get(property);
if (propertyValue === undefined || propertyValue === null) return this;
propertyValue = cloneDeep(propertyValue);

unsetByPath(propertyValue, nestedPath, '/');

Expand Down
6 changes: 6 additions & 0 deletions test/jointjs/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ QUnit.module('cell', function(hooks) {
assert.deepEqual(attributes.a[1], { cc: 'cc' });
});

QUnit.test('remove non-existing top-level property', function(assert) {

el.removeProp('a/b/c');
assert.equal(attributes.a, undefined);
});

QUnit.module('define path as an array', function(hooks) {

QUnit.test('remove item from array', function(assert) {
Expand Down

0 comments on commit f983f8d

Please sign in to comment.