Skip to content

Commit

Permalink
Merge pull request #423 from VEuPathDB/420-safeHtml-changes
Browse files Browse the repository at this point in the history
Add check for HTML entities in safeHtml util
  • Loading branch information
jernestmyers committed Aug 15, 2023
2 parents d67dec7 + e3e4a93 commit 4b7cd15
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/libs/wdk-client/src/Utils/ComponentUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@ export function safeHtml<P>(
Component: any = 'span'
): JSX.Element {
str = str ?? '';
if (str.indexOf('<') === -1) {
/**
* To improve performance, let's skip the element creation and innerHTML magic
* when we detect neither HTML nor an HTML entity in the string
*/
const isHtmlEntityFound = /(\&(.+?);)/.test(str);
if (str.indexOf('<') === -1 && !isHtmlEntityFound) {
return <Component {...props}>{str}</Component>;
}
// Use innerHTML to auto close tags
Expand Down

0 comments on commit 4b7cd15

Please sign in to comment.