Skip to content

Commit

Permalink
Fix leaking of one element's attribute values onto another (following…
Browse files Browse the repository at this point in the history
…) element during SVG parsing.
  • Loading branch information
kangax committed Apr 29, 2011
1 parent 7a28d27 commit 5c7440c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -7962,7 +7962,7 @@ fabric.util.animate = animate;
var parsedAttributes = fabric.parseAttributes(element, fabric.Rect.ATTRIBUTE_NAMES);
parsedAttributes = _setDefaultLeftTopValues(parsedAttributes);

var rect = new fabric.Rect(fabric.util.object.extend(options || { }, parsedAttributes));
var rect = new fabric.Rect(fabric.util.object.extend((options ? fabric.util.object.clone(options) : { }), parsedAttributes));
rect._normalizeLeftTopProperties(parsedAttributes);

return rect;
Expand Down
2 changes: 1 addition & 1 deletion src/rect.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
var parsedAttributes = fabric.parseAttributes(element, fabric.Rect.ATTRIBUTE_NAMES);
parsedAttributes = _setDefaultLeftTopValues(parsedAttributes);

var rect = new fabric.Rect(fabric.util.object.extend(options || { }, parsedAttributes));
var rect = new fabric.Rect(fabric.util.object.extend((options ? fabric.util.object.clone(options) : { }), parsedAttributes));
rect._normalizeLeftTopProperties(parsedAttributes);

return rect;
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/svg_with_rect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 5 additions & 10 deletions test/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,34 +253,29 @@
var path = data[0];

ok(path instanceof fabric.Path);
equals(EXPECTED_PATH_JSON, JSON.stringify(path.toJSON()));
equals(JSON.stringify(path.toJSON()), EXPECTED_PATH_JSON);
}
start();
}, 1500);
});

// https://github.com/kangax/fabric.js/issues/25
asyncTest('parseSVGDocument w. rect', function() {
asyncTest('parsing one element should not "leak" its "fill" value onto parsing of following element', function() {

var data;
var objects;
fabric.util.request('../fixtures/svg_with_rect.svg', {
method: 'get',
onComplete: function(resp) {
var doc = resp.responseXML;
fabric.parseSVGDocument(doc.documentElement, function() {
data = arguments[0];
objects = arguments[0];
});
}
});

setTimeout(function() {
equals(typeof data, 'object');
equals(data.length, 1);
equals(objects[1].fill, 'green');

if (data) {
var rect = data[0];
ok(rect instanceof fabric.Rect);
}
start();
}, 1500);
});
Expand Down

0 comments on commit 5c7440c

Please sign in to comment.