diff --git a/x-pack/platform/plugins/shared/ingest_pipelines/public/application/components/pipeline_editor/utils.test.ts b/x-pack/platform/plugins/shared/ingest_pipelines/public/application/components/pipeline_editor/utils.test.ts index 8b75afd985785..7a83ee89b0584 100644 --- a/x-pack/platform/plugins/shared/ingest_pipelines/public/application/components/pipeline_editor/utils.test.ts +++ b/x-pack/platform/plugins/shared/ingest_pipelines/public/application/components/pipeline_editor/utils.test.ts @@ -95,4 +95,53 @@ describe('convert processors to json', () => { customProcessor: "aaa\"bbb" }); }); + + it('preserves empty string values', () => { + const obj = { + field1: 'normalString', + value: '', + inference_config: '', + field_map: '', + params: '', + pattern_definitions: '', + processor: '', + customOptions: '', + }; + + const result = convertProccesorsToJson(obj); + + expect(result).toEqual({ + field1: 'normalString', + value: '', + inference_config: '', + field_map: '', + params: '', + pattern_definitions: '', + processor: '', + }); + + // Explicitly check that empty strings are preserved and not converted to undefined + expect(result.value).toBe(''); + expect(result.inference_config).toBe(''); + expect(result.field_map).toBe(''); + expect(result.params).toBe(''); + expect(result.pattern_definitions).toBe(''); + expect(result.processor).toBe(''); + }); + + it('handles null and undefined values correctly', () => { + const obj = { + value: null, + inference_config: undefined, + field_map: 'normalString', + }; + + const result = convertProccesorsToJson(obj); + + expect(result).toEqual({ + value: undefined, + inference_config: undefined, + field_map: 'normalString', + }); + }); }); diff --git a/x-pack/platform/plugins/shared/ingest_pipelines/public/application/components/pipeline_editor/utils.ts b/x-pack/platform/plugins/shared/ingest_pipelines/public/application/components/pipeline_editor/utils.ts index f8905be3d1284..cf85761dc30aa 100644 --- a/x-pack/platform/plugins/shared/ingest_pipelines/public/application/components/pipeline_editor/utils.ts +++ b/x-pack/platform/plugins/shared/ingest_pipelines/public/application/components/pipeline_editor/utils.ts @@ -129,10 +129,15 @@ const escapeLiteralStrings = (data: string): string[] => { }; const convertProcessorValueToJson = (data: string): any => { - if (!data) { + if (data === null || data === undefined) { return undefined; } + // Preserve empty strings + if (data === '') { + return data; + } + try { const escapedData = escapeLiteralStrings(data); return JSON.parse(escapedData.join(''));