From 37fae09ce46eb4d04c4cc652eb5b933e7be2b766 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Thu, 5 Aug 2021 01:05:34 +0200 Subject: [PATCH] #2219 Validating directives agains list of legal configuration keys --- src/defaultConfig.js | 11 +++++++++++ src/utils.js | 25 +++++++++++++++---------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/defaultConfig.js b/src/defaultConfig.js index 63d4554e1..42bdfcd4e 100644 --- a/src/defaultConfig.js +++ b/src/defaultConfig.js @@ -1142,4 +1142,15 @@ top of the chart config.class.arrowMarkerAbsolute = config.arrowMarkerAbsolute; config.git.arrowMarkerAbsolute = config.arrowMarkerAbsolute; +const keyify = (obj, prefix = '') => + Object.keys(obj).reduce((res, el) => { + if( Array.isArray(obj[el]) ) { + return res; + } else if( typeof obj[el] === 'object' && obj[el] !== null ) { + return [...res, prefix + el, ...keyify(obj[el],'')]; + } + return [...res, prefix + el]; + }, []); + +export const configKeys = keyify(config, ''); export default config; diff --git a/src/utils.js b/src/utils.js index f827b869c..9b485e29c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -14,6 +14,7 @@ import { select, } from 'd3'; import common from './diagrams/common/common'; +import { configKeys } from './defaultConfig'; import { log } from './logger'; // Effectively an enum of the supported curve types, accessible by name @@ -73,18 +74,22 @@ export const detectInit = function (text, cnf) { let args = inits.map((init) => init.args); Object.keys(args).forEach((argKey) => { Object.keys(args[argKey]).forEach((key) => { - if (key.indexOf('__') === 0) { - log.debug('sanitize deleting prototype option', args[key]); - delete args[argKey][key]; - } + // if (key.indexOf('__') === 0) { + // log.debug('sanitize deleting prototype option', args[key]); + // delete args[argKey][key]; + // } - if (key.indexOf('proto') >= 0) { - log.debug('sanitize deleting prototype option', args[key]); - delete args[argKey][key]; - } + // if (key.indexOf('proto') >= 0) { + // log.debug('sanitize deleting prototype option', args[key]); + // delete args[argKey][key]; + // } - if (key.indexOf('constr') >= 0) { - log.debug('sanitize deleting prototype option', args[key]); + // if (key.indexOf('constr') >= 0) { + // log.debug('sanitize deleting prototype option', args[key]); + // delete args[argKey][key]; + // } + if(configKeys.indexOf(key)<0) { + log.debug('sanitize deleting option', args[argKey][key]); delete args[argKey][key]; } });