Merge pull request #2256 from asturur/fix-style-parsing

Fix style parsing
This commit is contained in:
Juriy Zaytsev 2015-06-03 14:13:38 -04:00
commit d817ae6f63
2 changed files with 12 additions and 1 deletions

View file

@ -275,7 +275,7 @@
*/
function parseStyleString(style, oStyle) {
var attr, value;
style.replace(/;$/, '').split(';').forEach(function (chunk) {
style.replace(/;\s*$/, '').split(';').forEach(function (chunk) {
var pair = chunk.split(':');
attr = normalizeAttr(pair[0].trim().toLowerCase());

View file

@ -146,6 +146,17 @@
deepEqual(fabric.parseStyleAttribute(element), expectedObject);
});
test('parseStyleAttribute with trailing spaces', function() {
var element = fabric.document.createElement('path');
element.setAttribute('style', 'left:10px; top:5px; ');
var expectedObject = {
'left': 10,
'top': 5
};
deepEqual(fabric.parseStyleAttribute(element), expectedObject);
});
test('parseStyleAttribute with value normalization', function() {
var element = fabric.document.createElement('path');
element.setAttribute('style', 'fill:none; stroke-dasharray: 2 0.4;');