From ce9bdcc53f18603fcb6d7c4e53a977fed6bf11cc Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Mon, 29 May 2023 21:00:37 +0800 Subject: [PATCH] Fix exceptions for empty lines --- cypress/integration/rendering/sequencediagram.spec.js | 10 ++++++++++ packages/mermaid/src/utils.ts | 3 +++ 2 files changed, 13 insertions(+) diff --git a/cypress/integration/rendering/sequencediagram.spec.js b/cypress/integration/rendering/sequencediagram.spec.js index e5459637b..8ab21315f 100644 --- a/cypress/integration/rendering/sequencediagram.spec.js +++ b/cypress/integration/rendering/sequencediagram.spec.js @@ -88,6 +88,16 @@ context('Sequence diagram', () => { {} ); }); + it('should handle empty lines', () => { + imgSnapshotTest( + ` + sequenceDiagram + Alice->>John: Hello John
+ John-->>Alice: Great! + `, + {} + ); + }); it('should handle line breaks and wrap annotations', () => { imgSnapshotTest( ` diff --git a/packages/mermaid/src/utils.ts b/packages/mermaid/src/utils.ts index 6f824062d..3f70b2a7c 100644 --- a/packages/mermaid/src/utils.ts +++ b/packages/mermaid/src/utils.ts @@ -764,6 +764,9 @@ export const calculateTextDimensions: ( let cheight = 0; const dim = { width: 0, height: 0, lineHeight: 0 }; for (const line of lines) { + if (!line) { + continue; + } const textObj = getTextObj(); textObj.text = line; const textElem = drawSimpleText(g, textObj)