Merge pull request #6 from ianmiller347/development
remove jsdom and dompurify
This commit is contained in:
commit
42caa50f4a
@ -42,8 +42,5 @@
|
|||||||
"react": "^16.8.4",
|
"react": "^16.8.4",
|
||||||
"react-dom": "^16.8.4"
|
"react-dom": "^16.8.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {}
|
||||||
"dompurify": "^1.0.5",
|
|
||||||
"jsdom": "^12.0.0"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,33 +1,15 @@
|
|||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import DOMPurify from 'dompurify';
|
|
||||||
import { JSDOM } from 'jsdom';
|
|
||||||
// for now this icons json is generated via the build script from latest feather
|
// for now this icons json is generated via the build script from latest feather
|
||||||
// TODO: automatically generate this JSON via this repo's build script
|
// TODO: automatically generate this JSON via this repo's build script
|
||||||
import icons from './icons.json';
|
import icons from './icons.json';
|
||||||
|
|
||||||
class IconInner extends PureComponent {
|
class IconInner extends PureComponent {
|
||||||
createMarkup(markup) {
|
createMarkup(markup) {
|
||||||
// sanitize markup first:
|
// we dont sanitize markup
|
||||||
const sanitizedMarkup = this.sanitizeMarkup(markup);
|
// since icons.json is maintained within the package before build
|
||||||
|
// do the weird thing for dangerouslySetInnerHTML
|
||||||
// now do the weird thing for dangerouslySetInnerHTML
|
return { __html: markup };
|
||||||
return { __html: sanitizedMarkup };
|
|
||||||
}
|
|
||||||
|
|
||||||
sanitizeMarkup(markup) {
|
|
||||||
// For server environement
|
|
||||||
if (!window) {
|
|
||||||
// We create a window out of JSDOM
|
|
||||||
const window = (new JSDOM('')).window;
|
|
||||||
// Then we plug it to DOMPurify
|
|
||||||
const DOMPurifyServer = DOMPurify(window);
|
|
||||||
// and finally sanitize the markup
|
|
||||||
return DOMPurifyServer.sanitize(markup);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sanitize the markup
|
|
||||||
return DOMPurify.sanitize(markup);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -38,8 +20,7 @@ class IconInner extends PureComponent {
|
|||||||
|
|
||||||
if (iconMarkup) {
|
if (iconMarkup) {
|
||||||
// i didnt want to use dangerouslySetInnerHTML
|
// i didnt want to use dangerouslySetInnerHTML
|
||||||
// but i am sanitizing the markup first
|
// but this way I can just use the JSON to spit out SVG.
|
||||||
// and this way I can just use the JSON to spit out SVG
|
|
||||||
// another possible option is to use the feather lib functions
|
// another possible option is to use the feather lib functions
|
||||||
// which create the SVG files, then an SVG loader could be used.
|
// which create the SVG files, then an SVG loader could be used.
|
||||||
// i am open to this for a future version.
|
// i am open to this for a future version.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user