Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(template): Proxy Compile Input loses values from arrays #21943

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/util/template/index.spec.ts
Expand Up @@ -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();
});

Expand All @@ -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();
});
});
Expand Down
8 changes: 5 additions & 3 deletions lib/util/template/index.ts
Expand Up @@ -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)) {
Expand Down