Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-sequence-hang-missing-space-after-as.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mermaid': patch
---

fix: prevent sequence diagram hang when "as" is used without a trailing space in participant declarations
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<ID>[^<>:\n,;@\s]+(?=\s+as\s) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; }
<ID>[^<>:\n,;@]+(?=\s*[\n;#]|$) { yytext = yytext.trim(); this.popState(); return 'ACTOR'; }
<ID>[^<>:\n,;@]*\<[^\n]* { this.popState(); return 'INVALID'; }
<ID>[^\n]+ { yytext = yytext.trim(); this.popState(); return 'INVALID'; }
"box" { this.begin('LINE'); return 'box'; }
"participant" { this.begin('ID'); return 'participant'; }
"actor" { this.begin('ID'); return 'participant_actor'; }
Expand Down
14 changes: 14 additions & 0 deletions packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2622,6 +2622,20 @@ Bob->>Alice:Got it!
expect(error).toBe(true);
});

it('should not hang when "as" is used without a space before the alias text', async () => {
let errorMessage = '';
try {
await Diagram.fromText(`
sequenceDiagram
participant X_AutoPublishable asAAAAAAAAAAAAA:AAAAAAAAAAAAA
`);
} catch (e) {
errorMessage = e instanceof Error ? e.message : String(e);
}
expect(errorMessage).not.toBe('');
expect(errorMessage).not.toContain('Lexical error');
}, 5000);

it('should parse participant with stereotype and alias', async () => {
const diagram = await Diagram.fromText(`
sequenceDiagram
Expand Down
Loading