Markdown: Handle undefined/null strings (#18433)

This commit is contained in:
Tobias Skarhed 2019-08-07 13:25:09 +02:00 committed by Torkel Ödegaard
parent e8adbfea9f
commit 151b40ee2f
2 changed files with 10 additions and 2 deletions

View File

@ -0,0 +1,8 @@
import { renderMarkdown } from './markdown';
describe('Markdown wrapper', () => {
it('should be able to handle undefined value', () => {
const str = renderMarkdown(undefined);
expect(str).toBe('');
});
});

View File

@ -15,6 +15,6 @@ export function setMarkdownOptions(optionsOverride?: MarkedOptions) {
marked.setOptions({ ...defaultMarkedOptions, ...optionsOverride });
}
export function renderMarkdown(str: string): string {
return marked(str);
export function renderMarkdown(str?: string): string {
return marked(str || '');
}