From 09137875407f42149cedc9d2e25d06dbcc47e9ca Mon Sep 17 00:00:00 2001
From: Brenton Alker <brenton@tekerson.com>
Date: Wed, 3 May 2023 15:58:33 +1000
Subject: [PATCH] fix(template): Proxy Compile Input loses values from arrays
 (#21943)

---
 lib/util/template/index.spec.ts | 8 ++++++--
 lib/util/template/index.ts      | 8 +++++---
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/lib/util/template/index.spec.ts b/lib/util/template/index.spec.ts
index 286738231b..5318304e33 100644
--- a/lib/util/template/index.spec.ts
+++ b/lib/util/template/index.spec.ts
@@ -116,22 +116,25 @@ describe('util/template/index', () => {
 
   describe('proxyCompileInput', () => {
     const allowedField = 'body';
+    const allowedArrayField = 'prBodyNotes';
     const forbiddenField = 'foobar';
 
     type TestCompileInput = Record<
-      typeof allowedField | typeof forbiddenField,
+      typeof allowedField | typeof allowedArrayField | typeof forbiddenField,
       unknown
     >;
 
     const compileInput: TestCompileInput = {
       [allowedField]: 'allowed',
+      [allowedArrayField]: ['allowed'],
       [forbiddenField]: 'forbidden',
     };
 
-    it('accessing allowed files', () => {
+    it('accessing allowed fields', () => {
       const p = template.proxyCompileInput(compileInput);
 
       expect(p[allowedField]).toBe('allowed');
+      expect(p[allowedArrayField]).toStrictEqual(['allowed']);
       expect(p[forbiddenField]).toBeUndefined();
     });
 
@@ -153,6 +156,7 @@ describe('util/template/index', () => {
       const arr = proxy[allowedField] as TestCompileInput[];
       const obj = arr[0];
       expect(obj[allowedField]).toBe('allowed');
+      expect(obj[allowedArrayField]).toStrictEqual(['allowed']);
       expect(obj[forbiddenField]).toBeUndefined();
     });
   });
diff --git a/lib/util/template/index.ts b/lib/util/template/index.ts
index c4fcd4fcc5..f3e4a8809c 100644
--- a/lib/util/template/index.ts
+++ b/lib/util/template/index.ts
@@ -185,9 +185,11 @@ const compileInputProxyHandler: ProxyHandler<CompileInput> = {
     const value = target[prop];
 
     if (is.array(value)) {
-      return value
-        .filter(is.plainObject)
-        .map((element) => proxyCompileInput(element as CompileInput));
+      return value.map((element) =>
+        is.primitive(element)
+          ? element
+          : proxyCompileInput(element as CompileInput)
+      );
     }
 
     if (is.plainObject(value)) {
-- 
GitLab