From 0ffe9c8466b7f6dcd13ace7286f3d849e5921d69 Mon Sep 17 00:00:00 2001 From: Zeping Bai Date: Wed, 15 May 2024 18:45:49 +0800 Subject: [PATCH] fix: incorrect priority merge (#74) --- apps/cli/src/differ/differv3.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/cli/src/differ/differv3.ts b/apps/cli/src/differ/differv3.ts index 5b08567b..89f667df 100644 --- a/apps/cli/src/differ/differv3.ts +++ b/apps/cli/src/differ/differv3.ts @@ -628,7 +628,7 @@ export class DifferV3 { private mergeDefault(resource: ADCSDK.Resource, defaults: object): object { const defaultsClone = cloneDeep(defaults); const resourceClone = cloneDeep(resource); - const isObject = (val: unknown) => + const isObjectButNotArray = (val: unknown) => typeof val === 'object' && !Array.isArray(val); Object.entries(defaultsClone).forEach(([key, value]) => { @@ -636,12 +636,15 @@ export class DifferV3 { if (!resourceClone[key]) { // If the default value to be merged is an object and not an array, // it should not be merged. - if (isObject(value)) return; // include any array value + if (isObjectButNotArray(value) || Array.isArray(value)) return; // include any array value resourceClone[key] = value; } else { // If the default value and the value in the resource are both // objects, they need to be deeply merged, recursively it - if (isObject(value) && isObject(resourceClone[key])) + if ( + isObjectButNotArray(value) && + isObjectButNotArray(resourceClone[key]) + ) resourceClone[key] = this.mergeDefault(resourceClone[key], value); // If the default value is an array then the default value of the