mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
fix: remove dangerouslySetInnerHTML (#4181)
This commit is contained in:
parent
f995a0ed6c
commit
5388eaf48c
@ -1,4 +1,4 @@
|
||||
import { VFC } from 'react';
|
||||
import { Fragment, VFC } from 'react';
|
||||
import { safeRegExp } from '@server/util/escape-regex';
|
||||
import { styled } from '@mui/material';
|
||||
|
||||
@ -29,11 +29,18 @@ export const Highlighter: VFC<IHighlighterProps> = ({
|
||||
|
||||
const regex = safeRegExp(search, caseSensitive ? 'g' : 'gi');
|
||||
|
||||
return (
|
||||
<StyledSpan
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: children?.replaceAll(regex, '<mark>$&</mark>') || '',
|
||||
}}
|
||||
/>
|
||||
const parts = children.split(regex);
|
||||
|
||||
const highlightedText = parts.map((part, index) =>
|
||||
index < parts.length - 1 ? (
|
||||
<Fragment key={index}>
|
||||
{part}
|
||||
<mark>{search}</mark>
|
||||
</Fragment>
|
||||
) : (
|
||||
part
|
||||
)
|
||||
);
|
||||
|
||||
return <StyledSpan>{highlightedText}</StyledSpan>;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user