Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for empty <style/> tags #6169

Merged
merged 1 commit into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,8 @@

// very crude parsing of style contents
for (i = 0, len = styles.length; i < len; i++) {
// IE9 doesn't support textContent, but provides text instead.
var styleContents = styles[i].textContent || styles[i].text;
// <style/> could produce `undefined`, covering this case with ''
var styleContents = styles[i].textContent || '';

// remove comments
styleContents = styleContents.replace(/\/\*[\s\S]*?\*\//g, '');
Expand Down
13 changes: 13 additions & 0 deletions test/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,4 +760,17 @@
});
});

QUnit.test('parseSVGFromString with empty <style/>', function(assert) {
var done = assert.async();
var string = '<svg viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
' <style/>' +
' <rect width="10" height="10" />' +
'</svg>';

fabric.loadSVGFromString(string, function(objects) {
assert.equal(objects[0].type, 'rect');
done();
});
});

})();