mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-19 15:30:03 +02:00
#2560 Tetsing that the added css have balanced brackets
This commit is contained in:
16
src/utils.js
16
src/utils.js
@@ -974,6 +974,11 @@ export const directiveSanitizer = (args) => {
|
||||
log.debug('sanitize deleting constr option', key);
|
||||
delete args[key];
|
||||
}
|
||||
|
||||
if (key.indexOf('themeCSS') >= 0) {
|
||||
log.debug('sanitizing themeCss option');
|
||||
args[key] = sanitizeCss(args[key]);
|
||||
}
|
||||
if (configKeys.indexOf(key) < 0) {
|
||||
log.debug('sanitize deleting option', key);
|
||||
delete args[key];
|
||||
@@ -987,6 +992,16 @@ export const directiveSanitizer = (args) => {
|
||||
}
|
||||
}
|
||||
};
|
||||
export const sanitizeCss = (str) => {
|
||||
const stringsearch = 'o';
|
||||
const startCnt = (str.match(/\{/g) || []).length;
|
||||
const endCnt = (str.match(/\}/g) || []).length;
|
||||
if (startCnt !== endCnt) {
|
||||
return '{ /* ERROR: Unbalanced CSS */ }';
|
||||
}
|
||||
// Todo add more checks here
|
||||
return str;
|
||||
};
|
||||
|
||||
export default {
|
||||
assignWithDepth,
|
||||
@@ -1013,4 +1028,5 @@ export default {
|
||||
entityDecode,
|
||||
initIdGeneratior,
|
||||
directiveSanitizer,
|
||||
sanitizeCss,
|
||||
};
|
||||
|
Reference in New Issue
Block a user