-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow empty spaces un Gsub processor (#197815)
Closes [#191920](#191920) ## Summary In the pattern field of the GSUB processor, we were validating that the field is not empty. But for this case we must allow spaces as values. To fix this, I've added a second parameter `trimString` to the `emptyField` validator. If the parameter is set to true by default so the behavior of the validator doesn't change in all the fields that already use it. But when the parameter is set to false, as in this case, the entry value string is not trimmed, so it only validate to false if the field is actually empty. I also added some unit tests to make sure that this new condition doesn't break the validator. https://github.com/user-attachments/assets/049f7424-00c6-4bb2-ab89-2ce158ac4c4e #### Notes In the video it can be seen that a banner flashes when saving. It is a bug that already happened before this one. I've opened [an issue](#197810) to address it. (cherry picked from commit 2f7f8e3)
- Loading branch information
1 parent
d75024f
commit 906df14
Showing
4 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/plugins/es_ui_shared/static/forms/helpers/field_validators/empty_field.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { ValidationFuncArg } from '../../hook_form_lib'; | ||
import { emptyField } from './empty_field'; | ||
|
||
describe('emptyField', () => { | ||
const message = 'test error message'; | ||
const code = 'ERR_FIELD_MISSING'; | ||
const path = 'path'; | ||
|
||
const validator = (value: string | any[], trimString?: boolean) => | ||
emptyField(message, trimString)({ value, path } as ValidationFuncArg<any, any>); | ||
|
||
test('should return Validation function if value is an empty string and trimString is true', () => { | ||
expect(validator('')).toMatchObject({ message, code, path }); | ||
}); | ||
|
||
test('should return Validation function if value is an empty string and trimString is false', () => { | ||
expect(validator('', false)).toMatchObject({ message, code, path }); | ||
}); | ||
|
||
test('should return Validation function if value is a space and trimString is true', () => { | ||
expect(validator(' ')).toMatchObject({ message, code, path }); | ||
}); | ||
|
||
test('should return undefined if value is a space and trimString is false', () => { | ||
expect(validator(' ', false)).toBeUndefined(); | ||
}); | ||
|
||
test('should return undefined if value is a string and is not empty', () => { | ||
expect(validator('not Empty')).toBeUndefined(); | ||
}); | ||
|
||
test('should return undefined if value an array and is not empty', () => { | ||
expect(validator(['not Empty'])).toBeUndefined(); | ||
}); | ||
|
||
test('should return undefined if value an array and is empty', () => { | ||
expect(validator([])).toMatchObject({ message, code, path }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters