Skip to content

Commit 5ade451

Browse files
committed
III-6955: sanitize description on the event translation page
1 parent 098d7ac commit 5ade451

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

src/pages/TranslateForm.tsx

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,24 @@ import { FormElement } from '@/ui/FormElement';
1818
import { Inline } from '@/ui/Inline';
1919
import { Input } from '@/ui/Input';
2020
import { Page } from '@/ui/Page';
21+
import { Panel } from '@/ui/Panel';
2122
import { Stack } from '@/ui/Stack';
2223
import { Text } from '@/ui/Text';
2324
import { getGlobalBorderRadius, getValueFromTheme } from '@/ui/theme';
2425
import { Title } from '@/ui/Title';
2526
import { Toast } from '@/ui/Toast';
2627

28+
import {
29+
DescriptionPreview,
30+
dompurifySanitizeEventDescription,
31+
} from './events/[eventId]/preview/DescriptionPreview';
32+
2733
const htmlToDraft =
2834
typeof window === 'object' && require('html-to-draftjs').default;
2935

3036
const languageOptions = [...Object.values(SupportedLanguages), 'en'];
3137
const getGlobalValue = getValueFromTheme('global');
38+
const getTextValue = getValueFromTheme('text');
3239

3340
const TranslateForm = () => {
3441
const { t } = useTranslation();
@@ -88,7 +95,9 @@ const TranslateForm = () => {
8895
const newEditorStates: Record<string, EditorState> = {};
8996

9097
languageOptions.forEach((langValue) => {
91-
const description = offer.description?.[langValue];
98+
const description = dompurifySanitizeEventDescription(
99+
offer.description?.[langValue],
100+
);
92101

93102
if (description) {
94103
const draftState = htmlToDraft(description);
@@ -316,21 +325,30 @@ const TranslateForm = () => {
316325
</Text>
317326
{originalLanguage === language &&
318327
!isEditingOriginalDescription ? (
319-
<Inline>
320-
<Text variant="muted">
321-
{descriptionEditorStates[language]
322-
? descriptionEditorStates[language]
323-
.getCurrentContent()
324-
.getPlainText()
325-
: ''}
326-
</Text>
328+
<Stack spacing={3}>
329+
<Panel padding={3} color={getTextValue('muted.color')}>
330+
<DescriptionPreview
331+
description={
332+
descriptionEditorStates[language]
333+
? draftToHtml(
334+
convertToRaw(
335+
descriptionEditorStates[
336+
language
337+
].getCurrentContent(),
338+
),
339+
)
340+
: ''
341+
}
342+
/>
343+
</Panel>
344+
327345
<Button
328346
variant={ButtonVariants.LINK}
329347
onClick={toggleEditOriginalDescription}
330348
>
331349
{t('translate.change')}
332350
</Button>
333-
</Inline>
351+
</Stack>
334352
) : (
335353
<div id={`description-editor-container-${language}`}>
336354
<FormElement

src/pages/events/[eventId]/preview/DescriptionPreview.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ const DescriptionPreview = ({ description }: Props) => {
3030
color: ${getLinkThemeValue('hoverColor')};
3131
}
3232
}
33+
em {
34+
font-style: italic;
35+
}
36+
strong {
37+
font-weight: bold;
38+
}
3339
ul {
3440
list-style-type: disc;
3541
margin: 7.5px 0 7.5px 20px;

0 commit comments

Comments
 (0)