From 31fdd918e146f6d4f534ea3df5b3ceace0e23cfc Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 30 Nov 2023 18:11:28 +0100 Subject: [PATCH] fix: ensure no null serialized values end in UI server response payload MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../UIServiceWorkerBroadcastChannel.ts | 24 +++++++++---------- .../ui-services/AbstractUIService.ts | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts b/src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts index b385be7f..d3282916 100644 --- a/src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts +++ b/src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts @@ -70,31 +70,31 @@ export class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel { status: responsesStatus, hashIdsSucceeded: this.responses .get(uuid) - ?.responses.filter(({ hashId }) => !isNullOrUndefined(hashId)) - .map(({ status, hashId }) => { - if (status === ResponseStatus.SUCCESS) { + ?.responses.map(({ status, hashId }) => { + if (hashId !== undefined && status === ResponseStatus.SUCCESS) { return hashId; } - }) as string[], + }) + .filter((hashId) => !isNullOrUndefined(hashId)) as string[], ...(responsesStatus === ResponseStatus.FAILURE && { hashIdsFailed: this.responses .get(uuid) - ?.responses.filter(({ hashId }) => !isNullOrUndefined(hashId)) - .map(({ status, hashId }) => { - if (status === ResponseStatus.FAILURE) { + ?.responses.map(({ status, hashId }) => { + if (hashId !== undefined && status === ResponseStatus.FAILURE) { return hashId; } - }) as string[], + }) + .filter((hashId) => !isNullOrUndefined(hashId)) as string[], }), ...(responsesStatus === ResponseStatus.FAILURE && { responsesFailed: this.responses .get(uuid) - ?.responses.filter((response) => !isNullOrUndefined(response)) - .map((response) => { - if (response.status === ResponseStatus.FAILURE) { + ?.responses.map((response) => { + if (response !== undefined && response.status === ResponseStatus.FAILURE) { return response; } - }) as BroadcastChannelResponsePayload[], + }) + .filter((response) => !isNullOrUndefined(response)) as BroadcastChannelResponsePayload[], }), }; } diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index d7595c26..d0478b99 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -163,7 +163,7 @@ export abstract class AbstractUIService { if (isNotEmptyArray(payload.hashIds)) { payload.hashIds = payload.hashIds ?.map((hashId) => { - if (this.uiServer.chargingStations.has(hashId) === true) { + if (hashId !== undefined && this.uiServer.chargingStations.has(hashId) === true) { return hashId; } const msg = `${this.logPrefix( -- 2.34.1