Make sure only existent custom properties included in output. Closes #713

This commit is contained in:
kangax 2013-06-19 12:49:31 +02:00
parent 17551c0084
commit 6597b8919b
2 changed files with 21 additions and 1 deletions

View file

@ -286,7 +286,9 @@
function populateWithProperties(source, destination, properties) {
if (properties && Object.prototype.toString.call(properties) === '[object Array]') {
for (var i = 0, len = properties.length; i < len; i++) {
destination[properties[i]] = source[properties[i]];
if (properties[i] in source) {
destination[properties[i]] = source[properties[i]];
}
}
}
}

View file

@ -352,6 +352,24 @@
});
});
test('toJSON custom properties non-existence check', function() {
var rect = new fabric.Rect({ width: 10, height: 20 });
rect.padding = 123;
canvas.add(rect);
rect.foo = 'bar';
canvas.bar = 456;
var data = canvas.toJSON(['padding', 'foo', 'bar', 'baz']);
ok('padding' in data.objects[0]);
ok('foo' in data.objects[0], 'foo shouldn\'t be included if it\'s not in an object');
ok(!('bar' in data.objects[0]), 'bar shouldn\'t be included if it\'s not in an object');
ok(!('baz' in data.objects[0]), 'bar shouldn\'t be included if it\'s not in an object');
ok(!('foo' in data));
ok(!('baz' in data));
ok('bar' in data);
});
test('remove', function() {
ok(typeof canvas.remove == 'function');
var rect1 = makeRect(),