Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #364 from FormidableLabs/perf/disable-data-styles
Browse files Browse the repository at this point in the history
remove style whitelist filter
  • Loading branch information
boygirl authored Apr 19, 2018
2 parents 8f4ee49 + aacad73 commit b691033
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 66 deletions.
3 changes: 1 addition & 2 deletions src/victory-primitives/circle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import Collection from "../victory-util/collection";
import { sanitizeSvgStyle } from "../victory-util/style";

export default class Circle extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -31,7 +30,7 @@ export default class Circle extends React.Component {
className={className}
clipPath={clipPath}
transform={transform}
style={sanitizeSvgStyle(style)}
style={style}
role={role || "presentation"}
shapeRendering={shapeRendering || "auto"}
vectorEffect="non-scaling-stroke"
Expand Down
3 changes: 1 addition & 2 deletions src/victory-primitives/line.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import Collection from "../victory-util/collection";
import { sanitizeSvgStyle } from "../victory-util/style";

export default class Line extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -32,7 +31,7 @@ export default class Line extends React.Component {
className={className}
clipPath={clipPath}
transform={transform}
style={sanitizeSvgStyle(style)}
style={style}
role={role || "presentation"}
shapeRendering={shapeRendering || "auto"}
vectorEffect="non-scaling-stroke"
Expand Down
3 changes: 1 addition & 2 deletions src/victory-primitives/path.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import Collection from "../victory-util/collection";
import { sanitizeSvgStyle } from "../victory-util/style";

export default class Path extends React.Component {
static propTypes = {
Expand All @@ -27,7 +26,7 @@ export default class Path extends React.Component {
transform={transform}
className={className}
clipPath={clipPath}
style={sanitizeSvgStyle(style)}
style={style}
role={role || "presentation"}
shapeRendering={shapeRendering || "auto"}
{...events}
Expand Down
3 changes: 1 addition & 2 deletions src/victory-primitives/rect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import Collection from "../victory-util/collection";
import { sanitizeSvgStyle } from "../victory-util/style";

export default class Rect extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -34,7 +33,7 @@ export default class Rect extends React.Component {
x={x} y={y} rx={rx} ry={ry} width={width} height={height}
className={className}
clipPath={clipPath}
style={sanitizeSvgStyle(style)}
style={style}
transform={transform}
role={role || "presentation"}
shapeRendering={shapeRendering || "auto"}
Expand Down
3 changes: 1 addition & 2 deletions src/victory-primitives/text.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import Collection from "../victory-util/collection";
import { sanitizeSvgStyle } from "../victory-util/style";

export default class Text extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -35,7 +34,7 @@ export default class Text extends React.Component {
return (
<text
className={className} x={x} dx={dx} y={y} dy={dy}
transform={transform} style={sanitizeSvgStyle(style)}
transform={transform} style={style}
{...events}
>
{title && <title>{title}</title>}
Expand Down
3 changes: 1 addition & 2 deletions src/victory-primitives/tspan.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import Collection from "../victory-util/collection";
import { sanitizeSvgStyle } from "../victory-util/style";

export default class TSpan extends React.Component {
static propTypes = {
Expand All @@ -28,7 +27,7 @@ export default class TSpan extends React.Component {
<tspan
x={x} y={y} dx={dx} dy={dy} textAnchor={textAnchor}
className={className}
style={sanitizeSvgStyle(style)}
style={style}
{...events}
>
{content}
Expand Down
46 changes: 0 additions & 46 deletions src/victory-util/style.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,3 @@
import { pick } from "lodash";

/**
* Acceptable CSS/SVG style attributes
* https://reactjs.org/docs/dom-elements.html#all-supported-html-attributes
* non-style properties have been removed from this list
*/

const svgStyleWhitelist = [
"clipPath",
"cursor",
"fill",
"fillOpacity",
"filter",
"fontFamily",
"fontSize",
"fontWeight",
"height",
"markerEnd",
"markerMid",
"markerStart",
"mask",
"opacity",
"pointerEvents",
"points",
"stroke",
"strokeDasharray",
"strokeDashoffset",
"strokeLinecap",
"strokeLinejoin",
"strokeOpacity",
"strokeWidth",
"textAnchor",
"textDecoration",
"transform"
];

/**
* Given an object with CSS/SVG style attributes, return a new object containing
* only keys that are also on our SVG style whitelist.
* @param {Object} style An object of user-input style attributes.
* @returns {Object} An object containing only valid style data.
*/
export const sanitizeSvgStyle = function (style) {
return pick(style, svgStyleWhitelist);
};

/**
* Given an object with CSS/SVG transform definitions, return the string value
Expand Down
9 changes: 1 addition & 8 deletions test/client/spec/victory-util/style.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import Style, { sanitizeSvgStyle } from "src/victory-util/style";

describe("sanitizeSvgStyle", () => {
it("drop invalid svg attributes", () => {
const data = { tree: "blue", stroke: "#c43a31" };
expect(sanitizeSvgStyle(data)).to.deep.equal({ stroke: "#c43a31" });
});
});
import Style from "src/victory-util/style";

describe("toTransformString", () => {
it("returns an empty string if no transform definitions are given", () => {
Expand Down

0 comments on commit b691033

Please sign in to comment.