Skip to content

Commit

Permalink
Merge pull request #2256 from asturur/fix-style-parsing
Browse files Browse the repository at this point in the history
Fix style parsing
  • Loading branch information
kangax committed Jun 3, 2015
2 parents 023d293 + 4523835 commit d817ae6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
11 changes: 11 additions & 0 deletions test/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;');
Expand Down

0 comments on commit d817ae6

Please sign in to comment.