From 66a62eacdeb0698d62a881ab41ca2d380b9a14f9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 27 Mar 2023 20:57:46 +0200 Subject: [PATCH] fix: ensure charging profiles are deeply cloned before doing any treatment MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStationUtils.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 1059a1d0..bcedfb3a 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -330,17 +330,16 @@ export class ChargingStationUtils { ): number | undefined { let limit: number, matchingChargingProfile: ChargingProfile; // Get charging profiles for connector and sort by stack level - const chargingProfiles = Utils.cloneObject( - chargingStation - .getConnectorStatus(connectorId) - ?.chargingProfiles?.sort((a, b) => b.stackLevel - a.stackLevel) ?? [] - ); + const chargingProfiles = + Utils.cloneObject(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles)?.sort( + (a, b) => b.stackLevel - a.stackLevel + ) ?? []; // Get profiles on connector 0 if (chargingStation.getConnectorStatus(0)?.chargingProfiles) { chargingProfiles.push( - ...chargingStation - .getConnectorStatus(0) - .chargingProfiles.sort((a, b) => b.stackLevel - a.stackLevel) + ...Utils.cloneObject(chargingStation.getConnectorStatus(0).chargingProfiles).sort( + (a, b) => b.stackLevel - a.stackLevel + ) ); } if (Utils.isNotEmptyArray(chargingProfiles)) { -- 2.34.1