From 651274bc6f69b2c4b751c62a25453e9425ca8a0b Mon Sep 17 00:00:00 2001 From: Ibrahim Wassouf Date: Mon, 24 Jul 2023 21:23:21 -0300 Subject: [PATCH] Only allow quotes to wrap entire string --- .../src/diagrams/flowchart/parser/flow-text.spec.js | 12 +++--------- .../mermaid/src/diagrams/flowchart/parser/flow.jison | 4 +++- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow-text.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow-text.spec.js index 922508e80..ef72bb6b8 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow-text.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow-text.spec.js @@ -691,15 +691,9 @@ describe('[Text] when parsing', () => { expect(edges[0].text).toBe(',.?!+-*'); }); - it('should handle strings and text at the same time', function () { - const res = flow.parser.parse( - 'graph TD;A(this node has "string" and text)-->|this link has "string" and text|C;' - ); + it('should throw error for strings and text at the same time', function () { + const str = 'graph TD;A(this node has "string" and text)-->|this link has "string" and text|C;'; - const vert = flow.parser.yy.getVertices(); - const edges = flow.parser.yy.getEdges(); - - expect(vert['A'].text).toBe('this node has "string" and text'); - expect(edges[0].text).toBe('this link has "string" and text'); + expect(() => flow.parser.parse(str)).toThrowError("got 'STR'"); }); }); diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow.jison b/packages/mermaid/src/diagrams/flowchart/parser/flow.jison index 0219fec2d..7dbe3b4d4 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow.jison +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow.jison @@ -480,6 +480,8 @@ text: textToken { $$={text:$textToken, type: 'text'};} | text textToken { $$={text:$text.text+''+$textToken, type: $text.type};} + | STR + {$$={text: $STR, type: 'text'};} | MD_STR { $$={text: $MD_STR, type: 'markdown'};} ; @@ -567,7 +569,7 @@ styleComponent: NUM | NODE_STRING| COLON | UNIT | SPACE | BRKT | STYLE | PCT ; /* Token lists */ idStringToken : NUM | NODE_STRING | DOWN | MINUS | DEFAULT | COMMA | COLON; -textToken : STR | TEXT | TAGSTART | TAGEND | UNICODE_TEXT; +textToken : TEXT | TAGSTART | TAGEND | UNICODE_TEXT; textNoTagsToken: NUM | NODE_STRING | SPACE | MINUS | keywords | START_LINK ;