Fix leaking of one element's attribute values onto another (following) element during SVG parsing.

This commit is contained in:
kangax 2011-04-29 16:44:49 -04:00
parent 7a28d275a3
commit 5c7440cc13
4 changed files with 9 additions and 13 deletions

2
dist/all.js vendored
View file

@ -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;

View file

@ -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;

View file

@ -3,5 +3,6 @@
<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
]>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
<rect x="8.5" y="208" width="8.76" height="17.28" />
<rect height="100" width="100" y="50" x="50" fill="red" />
<circle r="25" cy="100" cx="100" fill="green" />
</svg>

Before

Width:  |  Height:  |  Size: 322 B

After

Width:  |  Height:  |  Size: 379 B

View file

@ -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);
});