From 6105185d05ef581afb2ac4bb42484e4860ae4068 Mon Sep 17 00:00:00 2001 From: Yash Singh Date: Tue, 16 Apr 2024 17:14:49 -0700 Subject: [PATCH] test: requirement, sankey --- .../src/diagrams/block/parser/block.spec.ts | 4 ---- .../src/diagrams/class/parser/class.spec.js | 4 ---- .../diagrams/flowchart/parser/flow.spec.js | 2 +- .../src/diagrams/gantt/parser/gantt.spec.js | 2 +- .../src/diagrams/git/gitGraphParserV2.spec.js | 2 +- .../parser/requirementDiagram.spec.js | 21 +++++++++++++++++++ .../src/diagrams/sankey/parser/sankey.spec.ts | 7 +++++++ 7 files changed, 31 insertions(+), 11 deletions(-) diff --git a/packages/mermaid/src/diagrams/block/parser/block.spec.ts b/packages/mermaid/src/diagrams/block/parser/block.spec.ts index c4fbe5483..295dabf89 100644 --- a/packages/mermaid/src/diagrams/block/parser/block.spec.ts +++ b/packages/mermaid/src/diagrams/block/parser/block.spec.ts @@ -415,10 +415,6 @@ columns 1 ).not.toThrow(); } - it('should work with a prototype property', function () { - validateProperty('prototype'); - }); - it('should work with a __proto__ property', function () { validateProperty('__proto__'); }); diff --git a/packages/mermaid/src/diagrams/class/parser/class.spec.js b/packages/mermaid/src/diagrams/class/parser/class.spec.js index 175887756..d5f1de276 100644 --- a/packages/mermaid/src/diagrams/class/parser/class.spec.js +++ b/packages/mermaid/src/diagrams/class/parser/class.spec.js @@ -13,10 +13,6 @@ describe('class diagram', function () { expect(() => parser.parse(`classDiagram\nnamespace ${prop} {\n\tclass A\n}`)).not.toThrow(); } - it('should work with a prototype property', function () { - validateProperty('prototype'); - }); - it('should work with a __proto__ property', function () { validateProperty('__proto__'); }); diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flow.spec.js b/packages/mermaid/src/diagrams/flowchart/parser/flow.spec.js index 368ec0595..0828852e1 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flow.spec.js +++ b/packages/mermaid/src/diagrams/flowchart/parser/flow.spec.js @@ -195,7 +195,7 @@ with a second line` ); }); - for (const unsafeProp of ['__proto__', 'constructor', 'prototype']) { + for (const unsafeProp of ['__proto__', 'constructor']) { it(`should work with node id ${unsafeProp}`, function () { const flowChart = `graph LR ${unsafeProp} --> A;`; diff --git a/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js b/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js index 52c1d93cd..281e9b6bd 100644 --- a/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js +++ b/packages/mermaid/src/diagrams/gantt/parser/gantt.spec.js @@ -257,7 +257,7 @@ row2`; } ); - it.each(['__proto__', 'constructor', 'prototype'])('should allow for a link to %s id', (prop) => { + it.each(['__proto__', 'constructor'])('should allow for a link to %s id', (prop) => { expect(() => parser.parse(`gantt dateFormat YYYY-MM-DD diff --git a/packages/mermaid/src/diagrams/git/gitGraphParserV2.spec.js b/packages/mermaid/src/diagrams/git/gitGraphParserV2.spec.js index be042b75e..28174e823 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphParserV2.spec.js +++ b/packages/mermaid/src/diagrams/git/gitGraphParserV2.spec.js @@ -1097,7 +1097,7 @@ describe('when parsing a gitGraph', function () { }); describe('unsafe properties', () => { - for (const prop of ['__proto__', 'constructor', 'prototype']) { + for (const prop of ['__proto__', 'constructor']) { it(`should work with custom commit id or branch name ${prop}`, () => { const str = `gitGraph commit id:"${prop}" diff --git a/packages/mermaid/src/diagrams/requirement/parser/requirementDiagram.spec.js b/packages/mermaid/src/diagrams/requirement/parser/requirementDiagram.spec.js index 7e4e26cde..dce62c6ed 100644 --- a/packages/mermaid/src/diagrams/requirement/parser/requirementDiagram.spec.js +++ b/packages/mermaid/src/diagrams/requirement/parser/requirementDiagram.spec.js @@ -578,4 +578,25 @@ line 2`; let foundRelationship = requirementDb.getRelationships()[0]; expect(foundRelationship.type).toBe(expectedType); }); + + for (const property of ['__proto__', 'constructor']) { + it(`will accept ${property} as requirement id`, function () { + reqDiagram.parser.parse(`requirementDiagram + requirement ${property} { + id: 1 + text: the test text. + risk: high + verifymethod: test + }`); + expect(reqDiagram.parser.yy.getRequirements().size).toBe(1); + }); + + it(`will accept ${property} as element id`, function () { + reqDiagram.parser.parse(`requirementDiagram + element ${property} { + type: simulation + }`); + expect(reqDiagram.parser.yy.getElements().size).toBe(1); + }); + } }); diff --git a/packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts b/packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts index 4517ca01f..a45b3d0eb 100644 --- a/packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts +++ b/packages/mermaid/src/diagrams/sankey/parser/sankey.spec.ts @@ -20,5 +20,12 @@ describe('Sankey diagram', function () { sankey.parser.parse(graphDefinition); }); + + it('allows __proto__ as id', function () { + sankey.parser.parse(prepareTextForParsing(`sankey-beta + __proto__,A,0.597 + A,__proto__,0.403 + `)); + }); }); });