Fix Ingest Pipelines Grok processor to accept patterns that contain escaped characters. (#137245) (#137866)

(cherry picked from commit 8b01dcf496)

Co-authored-by: CJ Cenizal <cj.cenizal@elastic.co>
This commit is contained in:
Kibana Machine 2022-08-02 11:33:02 -04:00 committed by GitHub
parent 2e256ddd27
commit 6047162cc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 6 deletions

View file

@ -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]);
});
});

View file

@ -105,7 +105,6 @@ export const ProcessorFormContainer: FunctionComponent<Props> = ({
if (isValid) {
const { type, fields: options } = data as FormData;
unsavedFormState.current = options;
onSubmit({

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import { flow } from 'lodash';
import React, { FunctionComponent } from 'react';
import { i18n } from '@kbn/i18n';
@ -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;
@ -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 = {
@ -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.',