mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-23 02:06:45 +02:00
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:
@@ -67,6 +67,48 @@ describe('class diagram, ', function () {
|
|||||||
parser.parse(str);
|
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() {
|
it('should handle generic class with brackets', function() {
|
||||||
const str =
|
const str =
|
||||||
'classDiagram\n' +
|
'classDiagram\n' +
|
||||||
@@ -79,8 +121,6 @@ describe('class diagram, ', function () {
|
|||||||
' flightNumber : Integer\n' +
|
' flightNumber : Integer\n' +
|
||||||
' departureTime : Date\n' +
|
' departureTime : Date\n' +
|
||||||
'}';
|
'}';
|
||||||
|
|
||||||
parser.parse(str);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle class definitions', function() {
|
it('should handle class definitions', function() {
|
||||||
|
@@ -14,6 +14,8 @@
|
|||||||
\s+ /* skip whitespace */
|
\s+ /* skip whitespace */
|
||||||
"classDiagram" return 'CLASS_DIAGRAM';
|
"classDiagram" return 'CLASS_DIAGRAM';
|
||||||
[\{] { this.begin("struct"); /*console.log('Starting struct');*/return 'STRUCT_START';}
|
[\{] { 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>\} { /*console.log('Ending struct');*/this.popState(); return 'STRUCT_STOP';}}
|
||||||
<struct>[\n] /* nothing */
|
<struct>[\n] /* nothing */
|
||||||
<struct>[^\{\}\n]* { /*console.log('lex-member: ' + yytext);*/ return "MEMBER";}
|
<struct>[^\{\}\n]* { /*console.log('lex-member: ' + yytext);*/ return "MEMBER";}
|
||||||
|
Reference in New Issue
Block a user