Skip to content

Commit

Permalink
Disable convertStyleToAttrs plugin by default
Browse files Browse the repository at this point in the history
Ref #1362 #1360

From the [spec](https://www.w3.org/TR/SVG11/styling.html#UsingPresentationAttributes):

> Presentation attributes have lower priority than other CSS style rules specified in author style sheets or ‘style’ attributes.

Though we replace inline styles with attributes without checking if
thare is any `<style>` element. This makes the plugin unsafe and it
should not be enabled by default.
  • Loading branch information
TrySound committed Feb 22, 2021
1 parent 9b97e06 commit f7ba06a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/convertStyleToAttrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports.type = 'perItem';

exports.active = true;
exports.active = false;

exports.description = 'converts style to attributes';

Expand Down
5 changes: 5 additions & 0 deletions test/svgo/_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ describe('svgo', () => {
const result = optimize('<svg />', { input: 'file', path: 'input.svg' });
expect(result.data).to.equal('<svg/>');
});
it('should preserve style specifity over attributes', async () => {
const [original, expected] = await parseFixture('style-specifity.svg');
const result = optimize(original, { input: 'file', path: 'input.svg', js2svg: { pretty: true } });
expect(normalize(result.data)).to.equal(expected);
});
});
17 changes: 17 additions & 0 deletions test/svgo/style-specifity.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f7ba06a

Please sign in to comment.