mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-17 19:24:10 +01:00
Add sanitize to properties and link in Sequence Diagram
This commit is contained in:
@@ -563,7 +563,8 @@ context('Sequence diagram', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
context('links', () => {
|
context('links', () => {
|
||||||
it('should support actor links and properties', () => {
|
it('should support actor links and properties EXPERIMENTAL: USE WITH CAUTION', () => {
|
||||||
|
//Be aware that the syntax for "properties" is likely to be changed.
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
%%{init: { "config": { "mirrorActors": true, "forceMenus": true }}}%%
|
%%{init: { "config": { "mirrorActors": true, "forceMenus": true }}}%%
|
||||||
@@ -583,7 +584,8 @@ context('Sequence diagram', () => {
|
|||||||
{ logLevel: 0, sequence: { mirrorActors: true, noteFontSize: 18, noteFontFamily: 'Arial' } }
|
{ logLevel: 0, sequence: { mirrorActors: true, noteFontSize: 18, noteFontFamily: 'Arial' } }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('should support actor links and properties when not mirrored', () => {
|
it('should support actor links and properties when not mirrored EXPERIMENTAL: USE WITH CAUTION', () => {
|
||||||
|
//Be aware that the syntax for "properties" is likely to be changed.
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
%%{init: { "config": { "mirrorActors": false, "forceMenus": true, "wrap": true }}}%%
|
%%{init: { "config": { "mirrorActors": false, "forceMenus": true, "wrap": true }}}%%
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import mermaidAPI from '../../mermaidAPI';
|
import mermaidAPI from '../../mermaidAPI';
|
||||||
import * as configApi from '../../config';
|
import * as configApi from '../../config';
|
||||||
import { log } from '../../logger';
|
import { log } from '../../logger';
|
||||||
|
import { sanitizeText } from '../common/common';
|
||||||
|
|
||||||
let prevActor = undefined;
|
let prevActor = undefined;
|
||||||
let actors = {};
|
let actors = {};
|
||||||
@@ -219,7 +220,8 @@ export const addLinks = function (actorId, text) {
|
|||||||
const actor = getActor(actorId);
|
const actor = getActor(actorId);
|
||||||
// JSON.parse the text
|
// JSON.parse the text
|
||||||
try {
|
try {
|
||||||
const links = JSON.parse(text.text);
|
let sanitizedText = sanitizeText(text.text, configApi.getConfig());
|
||||||
|
const links = JSON.parse(sanitizedText);
|
||||||
// add the deserialized text to the actor's links field.
|
// add the deserialized text to the actor's links field.
|
||||||
insertLinks(actor, links);
|
insertLinks(actor, links);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -232,9 +234,10 @@ export const addALink = function (actorId, text) {
|
|||||||
const actor = getActor(actorId);
|
const actor = getActor(actorId);
|
||||||
try {
|
try {
|
||||||
const links = {};
|
const links = {};
|
||||||
var sep = text.text.indexOf('@');
|
let sanitizedText = sanitizeText(text.text, configApi.getConfig());
|
||||||
var label = text.text.slice(0, sep - 1).trim();
|
var sep = sanitizedText.indexOf('@');
|
||||||
var link = text.text.slice(sep + 1).trim();
|
var label = sanitizedText.slice(0, sep - 1).trim();
|
||||||
|
var link = sanitizedText.slice(sep + 1).trim();
|
||||||
|
|
||||||
links[label] = link;
|
links[label] = link;
|
||||||
// add the deserialized text to the actor's links field.
|
// add the deserialized text to the actor's links field.
|
||||||
@@ -259,7 +262,8 @@ export const addProperties = function (actorId, text) {
|
|||||||
const actor = getActor(actorId);
|
const actor = getActor(actorId);
|
||||||
// JSON.parse the text
|
// JSON.parse the text
|
||||||
try {
|
try {
|
||||||
const properties = JSON.parse(text.text);
|
let sanitizedText = sanitizeText(text.text, configApi.getConfig());
|
||||||
|
const properties = JSON.parse(sanitizedText);
|
||||||
// add the deserialized text to the actor's property field.
|
// add the deserialized text to the actor's property field.
|
||||||
insertProperties(actor, properties);
|
insertProperties(actor, properties);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -976,7 +976,8 @@ link a: Tests @ https://tests.contoso.com/?svc=alice@contoso.com
|
|||||||
expect(actors.a.links["Tests"]).toBe("https://tests.contoso.com/?svc=alice@contoso.com");
|
expect(actors.a.links["Tests"]).toBe("https://tests.contoso.com/?svc=alice@contoso.com");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('it should handle properties', function () {
|
it('it should handle properties EXPERIMENTAL: USE WITH CAUTION', function () {
|
||||||
|
//Be aware that the syntax for "properties" is likely to be changed.
|
||||||
const str = `
|
const str = `
|
||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
participant a as Alice
|
participant a as Alice
|
||||||
|
|||||||
Reference in New Issue
Block a user