mirror of
				https://github.com/mermaid-js/mermaid.git
				synced 2025-10-31 02:44:17 +01: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); | ||||
|     }); | ||||
|  | ||||
|     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() { | ||||
|   | ||||
| @@ -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";} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Knut Sveidqvist
					Knut Sveidqvist