[Config] Fix handling of splittable subkeys when processing values (#190590)

## Summary

Follow up from https://github.com/elastic/kibana/pull/178841

## Release note

We fixed a bug when processing YAML configuration that contains dotted
notation in objects in arrays. This can manifest as a validation error
causing Kibana to not start.
This commit is contained in:
Jean-Louis Leysens 2024-08-15 15:47:36 +02:00 committed by GitHub
parent 2e7d67f893
commit 90a435cf8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 1 deletions

View file

@ -0,0 +1,7 @@
'[foo.bar]': "foobar"
list:
- id: "id1"
'[a.b]': ['foo', 'bar']
test.this.out: ['foo', 'bar']

View file

@ -131,6 +131,33 @@ test('supports unsplittable key syntax on nested list', () => {
`);
});
test('supports unsplittable key syntax on nested list with splittable subkeys', () => {
const config = getConfigFromFiles([fixtureFile('/unsplittable_3.yml')]);
expect(config).toMatchInlineSnapshot(`
Object {
"foo.bar": "foobar",
"list": Array [
Object {
"a.b": Array [
"foo",
"bar",
],
"id": "id1",
"test": Object {
"this": Object {
"out": Array [
"foo",
"bar",
],
},
},
},
],
}
`);
});
test('supports var:default syntax', () => {
process.env.KBN_ENV_VAR1 = 'val1';

View file

@ -59,7 +59,9 @@ function processEntryValue(value: any) {
delete value[subKey];
set(value, [unsplitKey], processEntryValue(subVal));
} else {
set(value, subKey, processEntryValue(subVal));
const subKeySplits = splitKey(subKey);
if (subKeySplits.length > 1) delete value[subKey];
set(value, subKeySplits, processEntryValue(subVal));
}
}
} else if (typeof value === 'string') {