Prevent Item#importJSON() from overriding Item#insert()

Closes #1392
This commit is contained in:
sasensi 2018-11-05 18:11:13 +01:00 committed by Jürg Lehni
parent eeb26436b0
commit 0eae0b6e4d
3 changed files with 17 additions and 1 deletions

View file

@ -10,6 +10,7 @@
- SVG Export: Fix error when `Item#matrix` is not invertible (#1580). - SVG Export: Fix error when `Item#matrix` is not invertible (#1580).
- SVG Import: Fix gradient default values (#1632). - SVG Import: Fix gradient default values (#1632).
- JSON Import: Prevent overriding `Item#insert()` (#1392).
# `0.12.1` # `0.12.1`

View file

@ -558,8 +558,16 @@ statics: /** @lends Base */{
if (args.length === 1 && obj instanceof Item if (args.length === 1 && obj instanceof Item
&& (useTarget || !(obj instanceof Layer))) { && (useTarget || !(obj instanceof Layer))) {
var arg = args[0]; var arg = args[0];
if (Base.isPlainObject(arg)) if (Base.isPlainObject(arg)) {
arg.insert = false; 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() // When reusing an object, initialize it through #set()
// instead of the constructor function: // instead of the constructor function:

View file

@ -256,3 +256,10 @@ test('Path#importJSON()', function() {
equals(function() { return layer.firstChild === path; }, true); equals(function() { return layer.firstChild === path; }, true);
equals(function() { return path.parent === layer; }, 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');
});