Sanitize tracker summaries

The summaries can include invalid html tags which caused issues when trying to render them since these tags do not exist.

Known issue:
The invalid tags will get escaped, however, when they include a space (e.g. "<Author's Notes>" everything after the space is missing (e.g. will be "<Author's>")
This commit is contained in:
schroda
2024-05-13 03:28:46 +02:00
parent c5d8b20528
commit d726793e3d
3 changed files with 51 additions and 5 deletions

View File

@@ -23,6 +23,7 @@ import parseHtml from 'html-react-parser';
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
import { useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import sanitizeHtml from 'sanitize-html';
import { SpinnerImage } from '@/components/util/SpinnerImage.tsx';
import { TrackerManga } from '@/lib/data/Trackers.ts';
import { TypographyMaxLines } from '@/components/atoms/TypographyMaxLines.tsx';
@@ -64,13 +65,12 @@ const TrackerMangaCardSummary = ({ summary }: { summary: string }) => {
setShowSummaryExpandButton(shouldCollapseSummary);
setIsSummaryExpanded(!shouldCollapseSummary);
}, []);
return (
<>
{summary.length && (
<Collapse collapsedSize={summaryCollapsedSize} in={isSummaryExpanded}>
<Typography ref={summaryRef} variant="body1" component="p">
{parseHtml(summary)}
{parseHtml(sanitizeHtml(summary, { disallowedTagsMode: 'escape' }))}
</Typography>
</Collapse>
)}