Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Fix: Handles incorrectly sanitized camelCase SVG attributes #491

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const AUTOBIND_BLACKLIST = {
};


const CAMEL_PROPS = /^(?:accent|alignment|arabic|baseline|cap|clip|color|fill|flood|font|glyph|horiz|marker|overline|paint|stop|strikethrough|stroke|text|underline|unicode|units|v|vector|vert|word|writing|x)[A-Z]/;

const CAMEL_PROPS = /^(?:accent|alignment|arabic|baseline|cap|clip(?!(PathUnits)$)|color|fill|flood|font|glyph(?!(Ref)$)|horiz|marker(?!(Height|Units|Width)$)|overline|paint|stop|strikethrough|stroke|text(?!(Length)$)|underline|unicode|units|v|vector|vert|word|writing|x(?!(ChannelSelector)$))[A-Z]/;

const BYPASS_HOOK = {};

Expand Down
50 changes: 50 additions & 0 deletions test/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,54 @@ describe('svg', () => {

expect(scratch.innerHTML).to.equal('<svg viewBox="0 0 100 100"><text text-anchor="mid">foo</text><path vector-effect="non-scaling-stroke" d="M0 0 L100 100"></path></svg>');
});

it("should render SVG to DOM with camelCased textLength", () => {
React.render(
<svg viewBox="0 0 100 100">
<text textAnchor="mid" textLength="100px">
foo
</text>
</svg>,
scratch
);

expect(scratch.innerHTML).to.equal(
'<svg viewBox="0 0 100 100"><text text-anchor="mid" textLength="100px">foo</text></svg>'
);
});

it("should render SVG to DOM with camelCased clipPathUnits", () => {
React.render(
<svg viewBox="0 0 100 100">
<clipPath id="myClip1" clipPathUnits="userSpaceOnUse" />
</svg>,
scratch
);

expect(scratch.innerHTML).to.equal(
'<svg viewBox="0 0 100 100"><clipPath id="myClip1" clipPathUnits="userSpaceOnUse"></clipPath></svg>'
);
});

it("should render SVG to DOM with camelCased marker attributes", () => {
React.render(
<svg viewBox="0 0 100 100">
<marker
id="arrow"
viewBox="0 0 10 10"
refX="5"
refY="5"
markerUnits="strokeWidth"
markerWidth="6"
markerHeight="6"
orient="auto-start-reverse"
/>
</svg>,
scratch
);

expect(scratch.innerHTML).to.equal(
'<svg viewBox="0 0 100 100"><marker id="arrow" viewBox="0 0 10 10" refX="5" refY="5" markerUnits="strokeWidth" markerWidth="6" markerHeight="6" orient="auto-start-reverse"></marker></svg>'
);
});
});