test: unsafe props to make sure they work with changes

This commit is contained in:
Yash Singh 2024-04-16 13:49:01 -07:00
parent 07de090723
commit 002aa29f19
5 changed files with 117 additions and 0 deletions

View File

@ -406,4 +406,23 @@ columns 1
expect(B.styles).toContain('fill:#f9F');
});
});
describe('prototype properties', function () {
function validateProperty(prop: string) {
expect(() => block.parse(`block-beta\n${prop}`)).not.toThrow();
expect(() => block.parse(`block-beta\nA; classDef ${prop} color:#ffffff,fill:#000000; class A ${prop}`)).not.toThrow();
}
it('should work with a prototype property', function () {
validateProperty('prototype');
});
it('should work with a __proto__ property', function () {
validateProperty('__proto__');
});
it('should work with a constructor property', function () {
validateProperty('constructor');
});
});
});

View File

@ -0,0 +1,28 @@
import { parser } from './classDiagram.jison';
import classDb from '../classDb.js';
describe('class diagram', function () {
beforeEach(function () {
parser.yy = classDb;
parser.yy.clear();
});
describe('prototype properties', function () {
function validateProperty(prop) {
expect(() => parser.parse(`classDiagram\nclass ${prop}`)).not.toThrow();
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__');
});
it('should work with a constructor property', function () {
validateProperty('constructor');
});
});
});

View File

@ -792,4 +792,22 @@ describe('when parsing ER diagram it...', function () {
expect(rels[0].relSpec.cardA).toBe(erDb.Cardinality.ZERO_OR_MORE);
});
});
describe('prototype properties', function () {
function validateProperty(prop) {
expect(() => erDiagram.parser.parse(`erDiagram\n${prop} ||--|{ ORDER : place`)).not.toThrow();
}
it('should work with a prototype property', function () {
validateProperty('prototype');
});
it('should work with a __proto__ property', function () {
validateProperty('__proto__');
});
it('should work with a constructor property', function () {
validateProperty('constructor');
});
})
});

View File

@ -194,4 +194,47 @@ describe('parsing a flow chart', function () {
with a second line`
);
});
for (const unsafeProp of ['__proto__', 'constructor', 'prototype']) {
it(`should work with node id ${unsafeProp}`, function () {
const flowChart = `graph LR
${unsafeProp} --> A;`;
expect(() => {
flow.parser.parse(flowChart);
}).not.toThrow();
});
it(`should work with tooltip id ${unsafeProp}`, function () {
const flowChart = `graph LR
click ${unsafeProp} callback "${unsafeProp}";`;
expect(() => {
flow.parser.parse(flowChart);
}).not.toThrow();
});
it(`should work with class id ${unsafeProp}`, function () {
const flowChart = `graph LR
${unsafeProp} --> A;
classDef ${unsafeProp} color:#ffffff,fill:#000000;
class ${unsafeProp} ${unsafeProp};`;
expect(() => {
flow.parser.parse(flowChart);
}).not.toThrow();
});
it(`should work with subgraph id ${unsafeProp}`, function () {
const flowChart = `graph LR
${unsafeProp} --> A;
subgraph ${unsafeProp}
C --> D;
end;`;
expect(() => {
flow.parser.parse(flowChart);
}).not.toThrow();
});
}
});

View File

@ -256,4 +256,13 @@ row2`;
expect(ganttDb.getWeekday()).toBe(day);
}
);
it.each(['__proto__', 'constructor', 'prototype'])('should allow for a link to %s id', (prop) => {
expect(() => parser.parse(`gantt
dateFormat YYYY-MM-DD
section Section
A task :${prop}, 2024-10-01, 3d
click ${prop} href "https://mermaid.js.org/"
`)).not.toThrow();
});
});