mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-17 19:24:10 +01:00
Better balance check
This commit is contained in:
18
src/utils.js
18
src/utils.js
@@ -1057,7 +1057,7 @@ export const directiveSanitizer = (args) => {
|
|||||||
for (let i = 0; i < kArr.length; i++) {
|
for (let i = 0; i < kArr.length; i++) {
|
||||||
const k = kArr[i];
|
const k = kArr[i];
|
||||||
const val = args.themeVariables[k];
|
const val = args.themeVariables[k];
|
||||||
if (!val.match(/^[a-zA-Z0-9#,";()%. ]+$/)) {
|
if (val && val.match && !val.match(/^[a-zA-Z0-9#,";()%. ]+$/)) {
|
||||||
args.themeVariables[k] = '';
|
args.themeVariables[k] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1065,9 +1065,19 @@ export const directiveSanitizer = (args) => {
|
|||||||
log.debug('After sanitization', args);
|
log.debug('After sanitization', args);
|
||||||
};
|
};
|
||||||
export const sanitizeCss = (str) => {
|
export const sanitizeCss = (str) => {
|
||||||
const stringsearch = 'o';
|
let startCnt = 0;
|
||||||
const startCnt = (str.match(/\{/g) || []).length;
|
let endCnt = 0;
|
||||||
const endCnt = (str.match(/\}/g) || []).length;
|
|
||||||
|
for (let i = 0; i < str.length; i++) {
|
||||||
|
if (startCnt < endCnt) {
|
||||||
|
return '{ /* ERROR: Unbalanced CSS */ }';
|
||||||
|
}
|
||||||
|
if (str[i] === '{') {
|
||||||
|
startCnt++;
|
||||||
|
} else if (str[i] === '}') {
|
||||||
|
endCnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (startCnt !== endCnt) {
|
if (startCnt !== endCnt) {
|
||||||
return '{ /* ERROR: Unbalanced CSS */ }';
|
return '{ /* ERROR: Unbalanced CSS */ }';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user