From 2a3de1a0904ea6748252295425e64be26ad7e204 Mon Sep 17 00:00:00 2001 From: Ashish Jain Date: Wed, 15 Jan 2020 20:29:13 +0100 Subject: [PATCH 1/3] #1206 Updated the classDiagram JISON to not allow EOF or another '{' until first one is closed --- src/diagrams/class/parser/classDiagram.jison | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/diagrams/class/parser/classDiagram.jison b/src/diagrams/class/parser/classDiagram.jison index 7bd768138..12e9a2564 100644 --- a/src/diagrams/class/parser/classDiagram.jison +++ b/src/diagrams/class/parser/classDiagram.jison @@ -14,6 +14,8 @@ \s+ /* skip whitespace */ "classDiagram" return 'CLASS_DIAGRAM'; [\{] { this.begin("struct"); /*console.log('Starting struct');*/return 'STRUCT_START';} +<> return "EOF_IN_STRUCT"; +[\{] return "OPEN_IN_STRUCT"; \} { /*console.log('Ending struct');*/this.popState(); return 'STRUCT_STOP';}} [\n] /* nothing */ [^\{\}\n]* { /*console.log('lex-member: ' + yytext);*/ return "MEMBER";} From 417d2c033692fe5341e7907cfb4c15b660a80ffd Mon Sep 17 00:00:00 2001 From: Ashish Jain Date: Wed, 15 Jan 2020 20:33:23 +0100 Subject: [PATCH 2/3] #1206 Added test case to verify parsing fails to allow another '{' until first one is closed --- src/diagrams/class/classDiagram.spec.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/diagrams/class/classDiagram.spec.js b/src/diagrams/class/classDiagram.spec.js index 8510b086d..f819e452d 100644 --- a/src/diagrams/class/classDiagram.spec.js +++ b/src/diagrams/class/classDiagram.spec.js @@ -67,6 +67,29 @@ describe('class diagram, ', function () { parser.parse(str); }); + it('should break when double { are encountered while defining generic class with brackets', function() { + const str = + 'classDiagram\n' + + 'class Dummy_Class~T~ {\n' + + 'String data\n' + + ' void methods()\n' + + '}\n' + + '\n' + + 'class Dummy_Class {\n' + + 'class Flight {\n' + + ' flightNumber : Integer\n' + + ' departureTime : Date\n' + + '}'; + let testPased =false; + try{ + parser.parse(str); + }catch (error){ + console.log(error.name); + testPased = true; + } + expect(testPased).toBe(true); + }); + it('should handle generic class with brackets', function() { const str = 'classDiagram\n' + @@ -79,8 +102,6 @@ describe('class diagram, ', function () { ' flightNumber : Integer\n' + ' departureTime : Date\n' + '}'; - - parser.parse(str); }); it('should handle class definitions', function() { From 99469f8404070306be37dca7267a1b6dc27bcf50 Mon Sep 17 00:00:00 2001 From: Ashish Jain Date: Wed, 15 Jan 2020 20:34:41 +0100 Subject: [PATCH 3/3] #1206 Added test case to verify parsing fails to allow EOF until first '{' is closed --- src/diagrams/class/classDiagram.spec.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/diagrams/class/classDiagram.spec.js b/src/diagrams/class/classDiagram.spec.js index f819e452d..4ac53ae10 100644 --- a/src/diagrams/class/classDiagram.spec.js +++ b/src/diagrams/class/classDiagram.spec.js @@ -67,7 +67,7 @@ describe('class diagram, ', function () { parser.parse(str); }); - it('should break when double { are encountered while defining generic class with brackets', function() { + it('should break when another `{`is encountered before closing the first one while defining generic class with brackets', function() { const str = 'classDiagram\n' + 'class Dummy_Class~T~ {\n' + @@ -90,6 +90,25 @@ describe('class diagram, ', function () { expect(testPased).toBe(true); }); + it('should break when EOF is encountered before closing the first `{` while defining generic class with brackets', function() { + const str = + 'classDiagram\n' + + 'class Dummy_Class~T~ {\n' + + 'String data\n' + + ' void methods()\n' + + '}\n' + + '\n' + + 'class Dummy_Class {\n'; + let testPased =false; + try{ + parser.parse(str); + }catch (error){ + console.log(error.name); + testPased = true; + } + expect(testPased).toBe(true); + }); + it('should handle generic class with brackets', function() { const str = 'classDiagram\n' +