From 968070436a1f0356a979b7b1465c0f5836917c22 Mon Sep 17 00:00:00 2001 From: Sotiri Bakagiannis Date: Mon, 7 Sep 2020 18:19:58 +0100 Subject: [PATCH] data/TrialHandler: fix attempted destructuring on non arrays When calling `Util.turnSquareBracketsIntoArrays()`, forget about destructuring ahead of checking whether the result is an array, just take the first element if it is. --- js/data/TrialHandler.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/js/data/TrialHandler.js b/js/data/TrialHandler.js index 314efcb..6efb1ad 100644 --- a/js/data/TrialHandler.js +++ b/js/data/TrialHandler.js @@ -473,11 +473,15 @@ export class TrialHandler extends PsychObject value = Number.parseFloat(value); } - const [arrayMaybe] = util.turnSquareBracketsIntoArrays(value); + // Look for string encoded arrays in the form of '[1, 2]' + const arrayMaybe = util.turnSquareBracketsIntoArrays(value); if (Array.isArray(arrayMaybe)) { - value = arrayMaybe; + // Keep the first match if more than one are found. If the + // input string looked like '[1, 2][3, 4]' for example, + // the resulting value would be [1, 2] + value = arrayMaybe[0]; } trial[fields[l]] = value;