From 05b221b1d619e6bb9c5abb1f432284dc1246bcd9 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 13 Sep 2022 22:29:38 +0200 Subject: [PATCH] fix: Deep copy options used by dropdown fields (#6425) This uncovered a broken test that was only passing because of a side effect of the dropdown option data getting modified. --- core/field_dropdown.ts | 2 ++ tests/mocha/json_test.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core/field_dropdown.ts b/core/field_dropdown.ts index 7c86653b3..cff223045 100644 --- a/core/field_dropdown.ts +++ b/core/field_dropdown.ts @@ -125,6 +125,8 @@ export class FieldDropdown extends Field { if (Array.isArray(menuGenerator)) { validateOptions(menuGenerator); + // Deep copy the option structure so it doesn't change. + menuGenerator = JSON.parse(JSON.stringify(menuGenerator)); } /** diff --git a/tests/mocha/json_test.js b/tests/mocha/json_test.js index 383b49130..a0905c576 100644 --- a/tests/mocha/json_test.js +++ b/tests/mocha/json_test.js @@ -275,7 +275,7 @@ suite('JSON Block Definitions', function() { const image1 = options[1][0]; assertImageEquals(IMAGE1, image1); - chai.assert.equal(IMAGE1.alt, IMAGE1_ALT_TEXT); // Via Msg reference + chai.assert.equal(image1.alt, IMAGE1_ALT_TEXT); // Via Msg reference chai.assert.equal(VALUE1, options[1][1]); const image2 = options[2][0];