mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +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 { safeRegExp } from '@server/util/escape-regex';
 | 
				
			||||||
import { styled } from '@mui/material';
 | 
					import { styled } from '@mui/material';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -29,11 +29,18 @@ export const Highlighter: VFC<IHighlighterProps> = ({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    const regex = safeRegExp(search, caseSensitive ? 'g' : 'gi');
 | 
					    const regex = safeRegExp(search, caseSensitive ? 'g' : 'gi');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return (
 | 
					    const parts = children.split(regex);
 | 
				
			||||||
        <StyledSpan
 | 
					
 | 
				
			||||||
            dangerouslySetInnerHTML={{
 | 
					    const highlightedText = parts.map((part, index) =>
 | 
				
			||||||
                __html: children?.replaceAll(regex, '<mark>$&</mark>') || '',
 | 
					        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