Skip to content

Commit 5e5d2db

Browse files
committed
used svgRenderer component by sanitizing svg content
1 parent 660eed6 commit 5e5d2db

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
3+
interface SVGRendererProps {
4+
svgContent: string;
5+
}
6+
7+
const SVGRenderer: React.FC<SVGRendererProps> = ({ svgContent }) => {
8+
const sanitizeSVG = (svg: string): string => {
9+
return svg
10+
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
11+
.replace(/\b(on\w+)="[^"]*"/gi, '');
12+
};
13+
14+
return (
15+
<span
16+
className="inline-block"
17+
dangerouslySetInnerHTML={{ __html: sanitizeSVG(svgContent) }}
18+
/>
19+
);
20+
};
21+
22+
export default SVGRenderer;

frontend/src/pages/About.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import SecondaryCard from 'components/SecondaryCard'
1313
import TopContributors from 'components/TopContributors'
1414
import { toaster } from 'components/ui/toaster'
1515
import UserCard from 'components/UserCard'
16-
16+
import SVGRenderer from 'components/skeletons/svgRenderer'
1717
const leaders = ['arkid15r', 'kasya', 'mamicidal']
1818

19+
1920
const About = () => {
2021
const [project, setProject] = useState<ProjectTypeGraphql | null>(null)
2122
const [isLoading, setIsLoading] = useState<boolean>(true)
@@ -91,11 +92,9 @@ const About = () => {
9192
<ul className="space-y-3">
9293
{Object.entries(tech.tools).map(([name, details]) => (
9394
<li key={name} className="flex flex-row items-center gap-2">
94-
<span
95-
className="text-xl"
96-
style={{ color: '#9ca3af' }}
97-
dangerouslySetInnerHTML={{ __html: details.icon }}
98-
/>
95+
<span className="text-xl" style={{ color: '#9ca3af' }}>
96+
<SVGRenderer svgContent={details.icon} />
97+
</span>
9998
<a
10099
href={details.url}
101100
className="text-gray-600 hover:underline dark:text-gray-300"

0 commit comments

Comments
 (0)