Skip to content

Commit

Permalink
[Ingest Pipelines] Fix gsub processor's replacement field serializati…
Browse files Browse the repository at this point in the history
…on (#175832)

Fixes #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.
  • Loading branch information
ElenaStoeva authored Feb 1, 2024
1 parent 415b925 commit 585630d
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
{
Expand Down

0 comments on commit 585630d

Please sign in to comment.