Skip to content
Snippets Groups Projects
Unverified Commit 0710513e authored by gabriellsh's avatar gabriellsh Committed by GitHub
Browse files

[FIX] MarkdownText component not respecting `Markdown_SupportSchemesForLink` setting (#27245)

parent fd086f6b
No related branches found
No related tags found
No related merge requests found
import { Box } from '@rocket.chat/fuselage';
import { useSetting } from '@rocket.chat/ui-contexts';
import dompurify from 'dompurify';
import { marked } from 'marked';
import React, { ComponentProps, FC, useMemo } from 'react';
......@@ -67,6 +68,11 @@ const inlineWithoutBreaksOptions = {
renderer: inlineWithoutBreaks,
};
const getRegexp = (schemeSetting: string): RegExp => {
const schemes = schemeSetting ? schemeSetting.split(',').join('|') : '';
return new RegExp(`^(${schemes}):`, 'gim');
};
const MarkdownText: FC<Partial<MarkdownTextParams>> = ({
content,
variant = 'document',
......@@ -79,6 +85,8 @@ const MarkdownText: FC<Partial<MarkdownTextParams>> = ({
let markedOptions: marked.MarkedOptions;
const schemes = useSetting('Markdown_SupportSchemesForLink') as string;
switch (variant) {
case 'inline':
markedOptions = inlineOptions;
......@@ -109,8 +117,8 @@ const MarkdownText: FC<Partial<MarkdownTextParams>> = ({
}
})();
return preserveHtml ? html : html && sanitizer(html, { ADD_ATTR: ['target'] });
}, [preserveHtml, sanitizer, content, variant, markedOptions, parseEmoji]);
return preserveHtml ? html : html && sanitizer(html, { ADD_ATTR: ['target'], ALLOWED_URI_REGEXP: getRegexp(schemes) });
}, [preserveHtml, sanitizer, content, variant, markedOptions, parseEmoji, schemes]);
return __html ? (
<Box
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment