diff --git a/src/parser.js b/src/parser.js index f34a6fb91c2..5cb066a07c7 100644 --- a/src/parser.js +++ b/src/parser.js @@ -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()); diff --git a/test/unit/parser.js b/test/unit/parser.js index 9a7939b15d1..5c65730ffd5 100644 --- a/test/unit/parser.js +++ b/test/unit/parser.js @@ -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;');