diff --git a/src/diagrams/sequence/parser/sequenceDiagram.jison b/src/diagrams/sequence/parser/sequenceDiagram.jison index 616b3f800..d5ba18b63 100644 --- a/src/diagrams/sequence/parser/sequenceDiagram.jison +++ b/src/diagrams/sequence/parser/sequenceDiagram.jison @@ -37,7 +37,7 @@ [0-9]+(?=[ \n]+) return 'NUM'; "participant" { this.begin('ID'); return 'participant'; } "actor" { this.begin('ID'); return 'participant_actor'; } -[^\->:\n,;]+?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; } +[^\->:\n,;]+?([\-]*[^\->:\n,;]+?)*?(?=((?!\n)\s)+"as"(?!\n)\s|[#\n;]|$) { yytext = yytext.trim(); this.begin('ALIAS'); return 'ACTOR'; } "as" { this.popState(); this.popState(); this.begin('LINE'); return 'AS'; } (?:) { this.popState(); this.popState(); return 'NEWLINE'; } "loop" { this.begin('LINE'); return 'loop'; } diff --git a/src/diagrams/sequence/sequenceDiagram.spec.js b/src/diagrams/sequence/sequenceDiagram.spec.js index 5b3d9b05d..af1abd20c 100644 --- a/src/diagrams/sequence/sequenceDiagram.spec.js +++ b/src/diagrams/sequence/sequenceDiagram.spec.js @@ -257,6 +257,28 @@ Bob-->Alice-in-Wonderland:I am good thanks!`; expect(messages[0].from).toBe('Alice-in-Wonderland'); expect(messages[1].from).toBe('Bob'); }); + + it('should handle dashes in participant names', function () { + const str = ` +sequenceDiagram +participant Alice-in-Wonderland +participant Bob +Alice-in-Wonderland->Bob:Hello Bob, how are - you? +Bob-->Alice-in-Wonderland:I am good thanks!`; + + mermaidAPI.parse(str); + const actors = diagram.db.getActors(); + expect(Object.keys(actors)).toEqual(['Alice-in-Wonderland', 'Bob']); + expect(actors['Alice-in-Wonderland'].description).toBe('Alice-in-Wonderland'); + expect(actors.Bob.description).toBe('Bob'); + + const messages = diagram.db.getMessages(); + + expect(messages.length).toBe(2); + expect(messages[0].from).toBe('Alice-in-Wonderland'); + expect(messages[1].from).toBe('Bob'); + }); + it('should alias participants', function () { const str = ` sequenceDiagram