mirror of
https://github.com/ansible/awx.git
synced 2026-01-19 05:31:22 -03:30
Check that host_filter is regexp
This commit is contained in:
parent
f04aff81c4
commit
dcf5917a4e
@ -3,7 +3,7 @@ import { withI18n } from '@lingui/react';
|
||||
import { t } from '@lingui/macro';
|
||||
import { useField } from 'formik';
|
||||
import { FormGroup } from '@patternfly/react-core';
|
||||
import { minMaxValue } from '../../../../util/validators';
|
||||
import { minMaxValue, regExp } from '../../../../util/validators';
|
||||
import AnsibleSelect from '../../../../components/AnsibleSelect';
|
||||
import { VariablesField } from '../../../../components/CodeMirrorInput';
|
||||
import FormField, {
|
||||
@ -192,6 +192,7 @@ export const HostFilterField = withI18n()(({ i18n }) => {
|
||||
)}
|
||||
name="host_filter"
|
||||
type="text"
|
||||
validate={regExp(i18n)}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
@ -88,3 +88,14 @@ export function combine(validators) {
|
||||
return undefined;
|
||||
};
|
||||
}
|
||||
|
||||
export function regExp(i18n) {
|
||||
return value => {
|
||||
try {
|
||||
RegExp(value);
|
||||
} catch {
|
||||
return i18n._(t`This field must be a regular expression`);
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import {
|
||||
noWhiteSpace,
|
||||
integer,
|
||||
combine,
|
||||
regExp,
|
||||
} from './validators';
|
||||
|
||||
const i18n = { _: val => val };
|
||||
@ -128,4 +129,13 @@ describe('validators', () => {
|
||||
});
|
||||
expect(combine(validators)('ok')).toBeUndefined();
|
||||
});
|
||||
|
||||
test('regExp rejects invalid regular expression', () => {
|
||||
expect(regExp(i18n)('[')).toEqual({
|
||||
id: 'This field must be a regular expression',
|
||||
});
|
||||
expect(regExp(i18n)('')).toBeUndefined();
|
||||
expect(regExp(i18n)('ok')).toBeUndefined();
|
||||
expect(regExp(i18n)('[^a-zA-Z]')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user