From 585630d0601011e5730392e340690502ba78ce5c Mon Sep 17 00:00:00 2001 From: Elena Stoeva <59341489+ElenaStoeva@users.noreply.github.com> Date: Thu, 1 Feb 2024 19:49:54 +0000 Subject: [PATCH] [Ingest Pipelines] Fix gsub processor's replacement field serialization (#175832) Fixes https://github.com/elastic/kibana/issues/170904 ## Summary This PR adds serialization to the `replacement` field in the Gsub processor edit form so that the field renders the text the way it is provided in the Es request, with unescaped special characters, if any exist. For example, we want `\n` to render the same, not to render as a new line (empty string) in the `replacement` field in the UI. ### Testing **Deserialization:** 1. Open Dev tools and create an ingest pipeline: ``` PUT _ingest/pipeline/my_pipeline_1 { "description": "My test pipeline", "processors": [ { "gsub": { "field": "message", "pattern": "\\\\n", "replacement": "\n" } }] } ``` 3. Run `GET _ingest/pipeline/my_pipeline_1` and observe the `replacement` fields (should be displayed as a new line). 4. Go to Stack Management -> Ingest Pipelines and start editing `my_pipeline_1`. The `replacement` field in the edit form should render as `\n` instead of an empty string. **Serialization:** 1. Go to Stack Management -> Ingest Pipelines and create a new pipeline `my_pipeline_2` with a Gsub processor on the field `message`, pattern: `\\\\n`, and replacement: `\n`. Save the pipeline 2. Go to Dev tools and get the pipeline: `GET _ingest/pipeline/my_pipeline_2`. The `replacement` field in the response should be displayed as a new line: ``` { "my_pipeline": { "description": "My test pipeline", "processors": [ { "gsub": { "field": "message", "pattern": """\\n""", "replacement": """ """ } } ] } } ``` 3. Edit the pipeline in the UI and change the `replacement` field to `\\n`. 4. Now the response in Dev tools should display `\n` (the new line character was escaped). You can also test with other escape characters. For example, creating a pipeline with a `my\ttab` replacement field in the UI should display `my tab` in the response. --- .../components/processor_form/processors/gsub.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/gsub.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/gsub.tsx index 11d06f3cca6fb..7e72848485c11 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/gsub.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/processor_form/processors/gsub.tsx @@ -52,6 +52,8 @@ const fieldsConfig: FieldsConfig = { label: i18n.translate('xpack.ingestPipelines.pipelineEditor.gsubForm.replacementFieldLabel', { defaultMessage: 'Replacement', }), + deserializer: flow(String, to.escapeBackslashes), + serializer: from.unescapeBackslashes, helpText: i18n.translate( 'xpack.ingestPipelines.pipelineEditor.gsubForm.replacementFieldHelpText', {