Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[v11] Limit MermaidConfig enum TypesScript types to certain values #4803

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: rewrite some config vals to tighten types
We're planning on limiting some of MermaidConfig's types to specific
values (e.g. `0 | 1` instead of `number`).
aloisklink committed Sep 2, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 77ba7c987aa218f2c3c1893dca401f5ef99a3120
2 changes: 1 addition & 1 deletion packages/mermaid/src/mermaidAPI.spec.ts
Original file line number Diff line number Diff line change
@@ -563,7 +563,7 @@ describe('mermaidAPI', () => {
const config = {
logLevel: 0,
securityLevel: 'loose',
};
} as const;
mermaidAPI.initialize(config);
mermaidAPI.setConfig({ securityLevel: 'strict', logLevel: 1 });
expect(mermaidAPI.getConfig().logLevel).toBe(1);
30 changes: 10 additions & 20 deletions packages/mermaid/src/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -260,56 +260,46 @@ describe('when formatting urls', function () {
it('should handle links', function () {
const url = 'https://mermaid-js.github.io/mermaid/#/';

const config = { securityLevel: 'loose' };
let result = utils.formatUrl(url, config);
let result = utils.formatUrl(url, { securityLevel: 'loose' });
expect(result).toEqual(url);

config.securityLevel = 'strict';
result = utils.formatUrl(url, config);
result = utils.formatUrl(url, { securityLevel: 'strict' });
expect(result).toEqual(url);
});
it('should handle anchors', function () {
const url = '#interaction';

const config = { securityLevel: 'loose' };
let result = utils.formatUrl(url, config);
let result = utils.formatUrl(url, { securityLevel: 'loose' });
expect(result).toEqual(url);

config.securityLevel = 'strict';
result = utils.formatUrl(url, config);
result = utils.formatUrl(url, { securityLevel: 'strict' });
expect(result).toEqual(url);
});
it('should handle mailto', function () {
const url = 'mailto:user@user.user';

const config = { securityLevel: 'loose' };
let result = utils.formatUrl(url, config);
let result = utils.formatUrl(url, { securityLevel: 'loose' });
expect(result).toEqual(url);

config.securityLevel = 'strict';
result = utils.formatUrl(url, config);
result = utils.formatUrl(url, { securityLevel: 'strict' });
expect(result).toEqual(url);
});
it('should handle other protocols', function () {
const url = 'notes://do-your-thing/id';

const config = { securityLevel: 'loose' };
let result = utils.formatUrl(url, config);
let result = utils.formatUrl(url, { securityLevel: 'loose' });
expect(result).toEqual(url);

config.securityLevel = 'strict';
result = utils.formatUrl(url, config);
result = utils.formatUrl(url, { securityLevel: 'strict' });
expect(result).toEqual(url);
});
it('should handle scripts', function () {
const url = 'javascript:alert("test")';

const config = { securityLevel: 'loose' };
let result = utils.formatUrl(url, config);
let result = utils.formatUrl(url, { securityLevel: 'loose' });
expect(result).toEqual(url);

config.securityLevel = 'strict';
result = utils.formatUrl(url, config);
result = utils.formatUrl(url, { securityLevel: 'strict' });
expect(result).toEqual('about:blank');
});
});