Merge pull request #1208 from mermaid-js/feature/Issue-1206_Parsing_Crashing_Browser_In_Class_Diagram

Feature/issue 1206 parsing crashing browser in class diagram
This commit is contained in:
Knut Sveidqvist 2020-01-15 20:55:21 +01:00 committed by GitHub
commit 921d274579
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 2 deletions

View File

@ -67,6 +67,48 @@ describe('class diagram, ', function () {
parser.parse(str);
});
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' +
'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 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' +
@ -79,8 +121,6 @@ describe('class diagram, ', function () {
' flightNumber : Integer\n' +
' departureTime : Date\n' +
'}';
parser.parse(str);
});
it('should handle class definitions', function() {

View File

@ -14,6 +14,8 @@
\s+ /* skip whitespace */
"classDiagram" return 'CLASS_DIAGRAM';
[\{] { this.begin("struct"); /*console.log('Starting struct');*/return 'STRUCT_START';}
<struct><<EOF>> return "EOF_IN_STRUCT";
<struct>[\{] return "OPEN_IN_STRUCT";
<struct>\} { /*console.log('Ending struct');*/this.popState(); return 'STRUCT_STOP';}}
<struct>[\n] /* nothing */
<struct>[^\{\}\n]* { /*console.log('lex-member: ' + yytext);*/ return "MEMBER";}