From 9eb47e4eeff895761459f8f4ffbd5f0050ede049 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Tue, 22 Jul 2025 09:18:24 +0300 Subject: [PATCH] [Ingest Pipelines] Fix empty string bug (#228717) (cherry picked from commit 462e7bd41ab3b23f4cc4a892b07a98255cbd85fa) --- .../components/pipeline_editor/utils.test.ts | 49 +++++++++++++++++++ .../components/pipeline_editor/utils.ts | 7 ++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.test.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.test.ts index bda9468cc718a..cedcfe1ee3cc1 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.test.ts +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.test.ts @@ -70,4 +70,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/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.ts index 81149830eb62b..eb0458070bc53 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.ts +++ b/x-pack/plugins/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(''));