From 63184d53c1dda1b36807cd2c087eed8eefee6047 Mon Sep 17 00:00:00 2001 From: abzicht Date: Sun, 10 Mar 2019 13:41:59 +0100 Subject: [PATCH] Argument processing now allows double quoted strings --- src/diagrams/gantt/ganttDb.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/diagrams/gantt/ganttDb.js b/src/diagrams/gantt/ganttDb.js index 2662e33ab..685472575 100644 --- a/src/diagrams/gantt/ganttDb.js +++ b/src/diagrams/gantt/ganttDb.js @@ -402,13 +402,28 @@ export const setClass = function (ids, className) { } const setClickFun = function (id, functionName, functionArgs) { - functionArgs = functionArgs.split(',') if (typeof functionName === 'undefined') { return } + + let argList = [] + if (typeof functionArgs === 'string') { + /* Splits functionArgs by ',', ignoring all ',' in double quoted strings */ + argList = functionArgs.split(/,(?=(?:(?:[^"]*"){2})*[^"]*$)/) + for (let i = 0; i < argList.length; i++) { + let item = argList[i].trim() + /* Removes all double quotes at the start and end of an argument */ + /* This preserves all starting and ending whitespace inside */ + if (item.charAt(0) === '"' && item.charAt(item.length - 1) === '"') { + item = item.substr(1, item.length - 2) + } + argList[i] = item + } + } + let rawTask = findTaskById(id) if (typeof rawTask !== 'undefined') { - pushFun(id, () => { window[functionName](id, ...functionArgs) }) + pushFun(id, () => { window[functionName](...argList) }) } }