From 0d2afc9c49a45523f2b772c2becbc97ade3de47f Mon Sep 17 00:00:00 2001 From: paulov Date: Sat, 18 May 2024 09:28:50 +0000 Subject: [PATCH] Fix RecursiveCloner Null Value Handling (!338) This PR fixes an issue in RecursiveCloner where null value properties of any type (i.e. arrays, nullable primitives) were being converted to empty objects. An example of where this is a problem can occur when starting a raid in 3.9. The client would attempt to convert the empty object (created by the RecursiveCloner) to an Array and it would result in a JSON error. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/338 Co-authored-by: paulov Co-committed-by: paulov --- project/src/utils/cloners/RecursiveCloner.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/project/src/utils/cloners/RecursiveCloner.ts b/project/src/utils/cloners/RecursiveCloner.ts index 751c781f..16a7a164 100644 --- a/project/src/utils/cloners/RecursiveCloner.ts +++ b/project/src/utils/cloners/RecursiveCloner.ts @@ -35,6 +35,14 @@ export class RecursiveCloner implements ICloner const newObj = {}; for (const propOf1 in obj) { + // If the value of the original property is null, ensure the cloned value is also null + // This fixes an issue where null arrays were incorrectly being converted to empty objects + if (obj[propOf1] === null) + { + newObj[propOf1.toString()] = null; + continue; + } + newObj[propOf1.toString()] = this.clone(obj[propOf1]); } return newObj as T;