diff --git a/CHANGELOG.md b/CHANGELOG.md index 793e6bc6..128d08b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - SVG Export: Fix error when `Item#matrix` is not invertible (#1580). - SVG Import: Fix gradient default values (#1632). +- JSON Import: Prevent overriding `Item#insert()` (#1392). # `0.12.1` diff --git a/src/core/Base.js b/src/core/Base.js index dce8d049..acad821d 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -558,8 +558,16 @@ statics: /** @lends Base */{ if (args.length === 1 && obj instanceof Item && (useTarget || !(obj instanceof Layer))) { var arg = args[0]; - if (Base.isPlainObject(arg)) + if (Base.isPlainObject(arg)) { arg.insert = false; + // When using target, make sure the `item.insert()` + // method is not overridden with the `arg.insert` + // property that was just set. Pass an exclude + // object to the call of `obj.set()` below (#1392). + if (useTarget) { + args = args.concat([{ insert: true }]) + } + } } // When reusing an object, initialize it through #set() // instead of the constructor function: diff --git a/test/tests/JSON.js b/test/tests/JSON.js index f8744224..656d63d2 100644 --- a/test/tests/JSON.js +++ b/test/tests/JSON.js @@ -256,3 +256,10 @@ test('Path#importJSON()', function() { equals(function() { return layer.firstChild === path; }, true); equals(function() { return path.parent === layer; }, true); }); + +test('Item#importJSON() does not override Item#insert()', function() { + var path = new Path(); + equals(typeof path.insert, 'function'); + path.importJSON(path.exportJSON()); + equals(typeof path.insert, 'function'); +});