File tree Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 33All notable changes to this project will be documented in this file.
44See [ Conventional Commits] ( https://conventionalcommits.org ) for commit guidelines.
55
6+ ### [ 3.0.2] ( https://github.com/codeskills-dev/md-to-react-email/compare/v3.0.1...v3.0.2 ) (2023-07-04)
7+
8+ ### Features
9+
10+ - Added checks to handle ` undefined | null | '' `
11+ - Added checks to handle input that is not of type ` string `
12+
613### [ 3.0.1] ( https://github.com/codeskills-dev/md-to-react-email/compare/v3.0.0...v3.0.1 ) (2023-07-04)
714
815### Features
Original file line number Diff line number Diff line change @@ -5,6 +5,36 @@ import {
55} from "../src" ;
66
77describe ( "Markdown to React Mail JSX Parser" , ( ) => {
8+ it ( "handles empty string correctly" , ( ) => {
9+ const markdown = "" ;
10+ const expected = `` ;
11+
12+ const rendered = parseMarkdownToReactEmailJSX ( {
13+ markdown,
14+ } ) ;
15+ expect ( rendered ) . toBe ( expected ) ;
16+ } ) ;
17+
18+ it ( "handles undefined string correctly" , ( ) => {
19+ const markdown = undefined as unknown as string ;
20+ const expected = `` ;
21+
22+ const rendered = parseMarkdownToReactEmailJSX ( {
23+ markdown,
24+ } ) ;
25+ expect ( rendered ) . toBe ( expected ) ;
26+ } ) ;
27+
28+ it ( "handles null string correctly" , ( ) => {
29+ const markdown = null as unknown as string ;
30+ const expected = `` ;
31+
32+ const rendered = parseMarkdownToReactEmailJSX ( {
33+ markdown,
34+ } ) ;
35+ expect ( rendered ) . toBe ( expected ) ;
36+ } ) ;
37+
838 it ( "converts header one correctly" , ( ) => {
939 const markdown = "# Hello, World!" ;
1040 const expected = `<h1 style="${ parseCssInJsToInlineCss (
Original file line number Diff line number Diff line change 11{
22 "name" : " md-to-react-email" ,
3- "version" : " 3.0.1 " ,
3+ "version" : " 3.0.2 " ,
44 "description" : " A simple Markdown parser for React-email written in typescript." ,
55 "keywords" : [
66 " markdown" ,
Original file line number Diff line number Diff line change @@ -207,6 +207,15 @@ export function parseMarkdownToReactEmailJSX({
207207 customStyles,
208208 withDataAttr = false ,
209209} : ParseMarkdownToReactEmailJSXProps ) : string {
210+ if (
211+ markdown === undefined ||
212+ markdown === null ||
213+ markdown === "" ||
214+ typeof markdown !== "string"
215+ ) {
216+ return "" ;
217+ }
218+
210219 const finalStyles = { ...styles , ...customStyles } ;
211220 let reactMailTemplate = "" ;
212221
You can’t perform that action at this time.
0 commit comments