From aaa22e3df0230b82ae20e8b0a530f247828d3a04 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Tue, 5 Apr 2022 09:39:32 +0200 Subject: [PATCH] fixes empty key value convert (#2370) * fixes empty key value convert * Update src/util.ts Co-authored-by: Jon Koops * fix linting issues * use some() Co-authored-by: Jon Koops --- src/util.test.ts | 12 ++++++++++++ src/util.ts | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/util.test.ts b/src/util.test.ts index a25fc68a5f..c4c58e096e 100644 --- a/src/util.test.ts +++ b/src/util.test.ts @@ -99,4 +99,16 @@ describe("Tests the form convert util functions", () => { }, }); }); + + it("convert empty to empty object", () => { + const given = { attributes: [{ key: "", value: "" }] }; + + //when + const values = convertFormValuesToObject(given); + + //then + expect(values).toEqual({ + attributes: {}, + }); + }); }); diff --git a/src/util.ts b/src/util.ts index 75806c5121..d7eaaa9a08 100644 --- a/src/util.ts +++ b/src/util.ts @@ -73,7 +73,10 @@ const isAttributeArray = (value: any) => { if (!Array.isArray(value)) { return false; } - return value.filter((e) => e.key && e.value).length !== 0; + + return value.some( + (e) => Object.hasOwn(e, "key") && Object.hasOwn(e, "value") + ); }; const isEmpty = (obj: any) => Object.keys(obj).length === 0;