Skip to content

Commit

Permalink
Fix Ingest Pipelines Grok processor to accept patterns that contain e…
Browse files Browse the repository at this point in the history
…scaped characters. (elastic#137245)

(cherry picked from commit 8b01dcf)
  • Loading branch information
CJ Cenizal committed Aug 2, 2022
1 parent c6a97f0 commit 2c301b1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,26 @@ describe('Processor: Grok', () => {
patterns: ['pattern1', 'pattern2', 'pattern3'],
});
});

test('accepts grok pattern that contains escaped characters', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;

// Add "field" value
form.setInputValue('fieldNameField.input', 'test_grok_processor');

// Add the escaped value of \[%{HTTPDATE:timestamp}\]%{SPACE}\"%{WORD:http_method}%{SPACE}HTTP/%{NUMBER:http_version}\"
const escapedValue =
'\\[%{HTTPDATE:timestamp}\\]%{SPACE}\\"%{WORD:http_method}%{SPACE}HTTP/%{NUMBER:http_version}\\"';
form.setInputValue('droppableList.input-0', escapedValue);

// Save the field
await saveNewProcessor();

const processors = getProcessorValue(onUpdate, GROK_TYPE);

expect(processors[0][GROK_TYPE].patterns).toEqual([escapedValue]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ export const ProcessorFormContainer: FunctionComponent<Props> = ({

if (isValid) {
const { type, fields: options } = data as FormData;

unsavedFormState.current = options;

onSubmit({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { flow } from 'lodash';
import React, { FunctionComponent } from 'react';
import { i18n } from '@kbn/i18n';

Expand All @@ -23,7 +22,7 @@ import { XJsonEditor, DragAndDropTextList } from '../field_components';

import { FieldNameField } from './common_fields/field_name_field';
import { IgnoreMissingField } from './common_fields/ignore_missing_field';
import { FieldsConfig, to, from, EDITOR_PX_HEIGHT, isJSONStringValidator } from './shared';
import { FieldsConfig, to, from, EDITOR_PX_HEIGHT } from './shared';

const { isJsonField, emptyField } = fieldValidators;

Expand All @@ -49,7 +48,6 @@ const patternsValidation: ValidationFunc<any, string, ArrayItem[]> = ({ value, f

const patternValidations: Array<ValidationFunc<any, string, string>> = [
emptyField(valueRequiredMessage),
isJSONStringValidator,
];

const fieldsConfig: FieldsConfig = {
Expand All @@ -58,8 +56,7 @@ const fieldsConfig: FieldsConfig = {
label: i18n.translate('xpack.ingestPipelines.pipelineEditor.grokForm.patternsFieldLabel', {
defaultMessage: 'Patterns',
}),
deserializer: flow(String, to.escapeBackslashes),
serializer: from.unescapeBackslashes,
deserializer: String,
helpText: i18n.translate('xpack.ingestPipelines.pipelineEditor.grokForm.patternsHelpText', {
defaultMessage:
'Grok expressions used to match and extract named capture groups. Uses the first matching expression.',
Expand Down

0 comments on commit 2c301b1

Please sign in to comment.