Skip to content

Commit

Permalink
Add empty string validation for Tags and Authors
Browse files Browse the repository at this point in the history
  • Loading branch information
machadoum committed Jun 9, 2021
1 parent 520d1e8 commit fbd3ace
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { ValidationFunc, ERROR_CODE, ValidationError } from '../../../../shared_imports';

export const emptyArrayItem = (message: string) => (
...[{ value }]: Parameters<ValidationFunc>
): ValidationError<ERROR_CODE> | void | undefined => {
if (typeof value !== 'string') {
return;
}

return value.trim() === ''
? {
code: 'ERR_INVALID_CHARS',
message,
}
: undefined;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { AboutStepRule } from '../../../pages/detection_engine/rules/types';
import { OptionalFieldLabel } from '../optional_field_label';
import { isUrlInvalid } from '../../../../common/utils/validators';
import * as I18n from './translations';
import { emptyArrayItem } from './field_validators';

const { emptyField } = fieldValidators;

Expand All @@ -38,6 +39,19 @@ export const schema: FormSchema<AboutStepRule> = {
}
),
labelAppend: OptionalFieldLabel,
validations: [
{
validator: emptyArrayItem(
i18n.translate(
'xpack.securitySolution.detectionEngine.createRule.stepAboutRule.tagFieldEmptyError',
{
defaultMessage: 'An author must not be empty',
}
)
),
type: 'arrayItem',
},
],
},
name: {
type: FIELD_TYPES.TEXT,
Expand Down Expand Up @@ -243,6 +257,19 @@ export const schema: FormSchema<AboutStepRule> = {
}
),
labelAppend: OptionalFieldLabel,
validations: [
{
validator: emptyArrayItem(
i18n.translate(
'xpack.securitySolution.detectionEngine.createRule.stepAboutRule.tagFieldEmptyError',
{
defaultMessage: 'A tag must not be empty',
}
)
),
type: 'arrayItem',
},
],
},
note: {
type: FIELD_TYPES.TEXTAREA,
Expand Down

0 comments on commit fbd3ace

Please sign in to comment.