From d36f45ec58723ae35df657fdc1fe377e4216d44e Mon Sep 17 00:00:00 2001 From: Cory Gwin Date: Thu, 7 Apr 2022 18:36:30 +0000 Subject: [PATCH 1/2] feat: add sanitization consistently --- src/diagrams/er/erDb.js | 9 +++++++-- src/diagrams/gantt/ganttDb.js | 7 ++++++- src/diagrams/user-journey/journeyDb.js | 6 +++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/diagrams/er/erDb.js b/src/diagrams/er/erDb.js index 8fe54ed83a..4186fd6d81 100644 --- a/src/diagrams/er/erDb.js +++ b/src/diagrams/er/erDb.js @@ -1,12 +1,15 @@ import { log } from '../../logger'; import mermaidAPI from '../../mermaidAPI'; import * as configApi from '../../config'; +import common from '../common/common'; let entities = {}; let relationships = []; let title = ''; let description = ''; +const sanitizeText = (txt) => common.sanitizeText(txt, configApi.getConfig()); + const Cardinality = { ZERO_OR_ONE: 'ZERO_OR_ONE', ZERO_OR_MORE: 'ZERO_OR_MORE', @@ -69,7 +72,8 @@ const getRelationships = () => relationships; // Keep this - TODO: revisit...allow the diagram to have a title const setTitle = function (txt) { - title = txt; + let sanitizedText = sanitizeText(txt, configApi.getConfig()); + title = sanitizedText; }; const getTitle = function () { @@ -77,7 +81,8 @@ const getTitle = function () { }; const setAccDescription = function (txt) { - description = txt; + let sanitizedText = sanitizeText(txt, configApi.getConfig()); + description = sanitizedText; }; const getAccDescription = function () { diff --git a/src/diagrams/gantt/ganttDb.js b/src/diagrams/gantt/ganttDb.js index 88c5915209..01663d9542 100644 --- a/src/diagrams/gantt/ganttDb.js +++ b/src/diagrams/gantt/ganttDb.js @@ -4,6 +4,10 @@ import { log } from '../../logger'; import * as configApi from '../../config'; import utils from '../../utils'; import mermaidAPI from '../../mermaidAPI'; +import common from '../common/common'; + +const sanitizeText = (txt) => common.sanitizeText(txt, configApi.getConfig()); + let dateFormat = ''; let axisFormat = ''; @@ -108,7 +112,8 @@ export const getLinks = function () { }; export const setTitle = function (txt) { - title = txt; + let sanitizedText = sanitizeText(txt, configApi.getConfig()); + title = sanitizedText; }; export const getTitle = function () { diff --git a/src/diagrams/user-journey/journeyDb.js b/src/diagrams/user-journey/journeyDb.js index 0452bd4a8d..6e32c0f1f5 100644 --- a/src/diagrams/user-journey/journeyDb.js +++ b/src/diagrams/user-journey/journeyDb.js @@ -1,5 +1,7 @@ import mermaidAPI from '../../mermaidAPI'; import * as configApi from '../../config'; +import common from '../common/common'; +const sanitizeText = (txt) => common.sanitizeText(txt, configApi.getConfig()); let title = ''; let currentSection = ''; @@ -21,7 +23,9 @@ export const clear = function () { }; export const setTitle = function (txt) { - title = txt; + let sanitizedText = sanitizeText(txt, configApi.getConfig()); + title = sanitizedText; + }; export const getTitle = function () { From 5452cedc517e40f46ac61e43e544800c7e71ab6a Mon Sep 17 00:00:00 2001 From: Cory Gwin Date: Fri, 8 Apr 2022 13:38:45 +0000 Subject: [PATCH 2/2] always use the same setup --- src/diagrams/er/erDb.js | 6 ++---- src/diagrams/gantt/ganttDb.js | 5 +---- src/diagrams/pie/pieDb.js | 1 - src/diagrams/user-journey/journeyDb.js | 3 +-- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/diagrams/er/erDb.js b/src/diagrams/er/erDb.js index 4186fd6d81..6f537f27f4 100644 --- a/src/diagrams/er/erDb.js +++ b/src/diagrams/er/erDb.js @@ -8,8 +8,6 @@ let relationships = []; let title = ''; let description = ''; -const sanitizeText = (txt) => common.sanitizeText(txt, configApi.getConfig()); - const Cardinality = { ZERO_OR_ONE: 'ZERO_OR_ONE', ZERO_OR_MORE: 'ZERO_OR_MORE', @@ -72,7 +70,7 @@ const getRelationships = () => relationships; // Keep this - TODO: revisit...allow the diagram to have a title const setTitle = function (txt) { - let sanitizedText = sanitizeText(txt, configApi.getConfig()); + let sanitizedText = common.sanitizeText(txt, configApi.getConfig()); title = sanitizedText; }; @@ -81,7 +79,7 @@ const getTitle = function () { }; const setAccDescription = function (txt) { - let sanitizedText = sanitizeText(txt, configApi.getConfig()); + let sanitizedText = common.sanitizeText(txt, configApi.getConfig()); description = sanitizedText; }; diff --git a/src/diagrams/gantt/ganttDb.js b/src/diagrams/gantt/ganttDb.js index 01663d9542..27c7d4dcbd 100644 --- a/src/diagrams/gantt/ganttDb.js +++ b/src/diagrams/gantt/ganttDb.js @@ -6,9 +6,6 @@ import utils from '../../utils'; import mermaidAPI from '../../mermaidAPI'; import common from '../common/common'; -const sanitizeText = (txt) => common.sanitizeText(txt, configApi.getConfig()); - - let dateFormat = ''; let axisFormat = ''; let todayMarker = ''; @@ -112,7 +109,7 @@ export const getLinks = function () { }; export const setTitle = function (txt) { - let sanitizedText = sanitizeText(txt, configApi.getConfig()); + let sanitizedText = common.sanitizeText(txt, configApi.getConfig()); title = sanitizedText; }; diff --git a/src/diagrams/pie/pieDb.js b/src/diagrams/pie/pieDb.js index 47592b211d..0ed02a4a9b 100644 --- a/src/diagrams/pie/pieDb.js +++ b/src/diagrams/pie/pieDb.js @@ -2,7 +2,6 @@ import { log } from '../../logger'; import mermaidAPI from '../../mermaidAPI'; import * as configApi from '../../config'; import common from '../common/common'; -const sanitizeText = (txt) => common.sanitizeText(txt, configApi.getConfig()); let sections = {}; let title = ''; diff --git a/src/diagrams/user-journey/journeyDb.js b/src/diagrams/user-journey/journeyDb.js index 6e32c0f1f5..ff2eda876e 100644 --- a/src/diagrams/user-journey/journeyDb.js +++ b/src/diagrams/user-journey/journeyDb.js @@ -1,7 +1,6 @@ import mermaidAPI from '../../mermaidAPI'; import * as configApi from '../../config'; import common from '../common/common'; -const sanitizeText = (txt) => common.sanitizeText(txt, configApi.getConfig()); let title = ''; let currentSection = ''; @@ -23,7 +22,7 @@ export const clear = function () { }; export const setTitle = function (txt) { - let sanitizedText = sanitizeText(txt, configApi.getConfig()); + let sanitizedText = common.sanitizeText(txt, configApi.getConfig()); title = sanitizedText; };