Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const CATEGORIZATION_REVIEW_MAX_CYCLES = 5;
export const CATEGORIZATION_RECURSION_LIMIT = 50;

// Name regex pattern
export const NAME_REGEX_PATTERN = /^[a-z0-9_]+$/;
export const NAME_REGEX_PATTERN = /^[a-z_][a-z0-9_]+$/;

// Datastream name regex pattern. Same regex that for the name validation in elastic-package
export const DATASTREAM_NAME_REGEX_PATTERN = /^([a-z0-9]{2}|[a-z0-9][a-z0-9_]+[a-z0-9])$/;
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export const DataStreamStep = React.memo<DataStreamStepProps>(
<EuiFieldText
name="name"
data-test-subj="nameInput"
value={name}
value={isValidName(name) ? name : ''}
onChange={onChange.name}
isInvalid={invalidFields.name}
isLoading={isLoadingPackageNames}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const NO_SPACES_HELP = i18n.translate(
'xpack.automaticImport.step.dataStream.noSpacesHelpText',
{
defaultMessage:
'Name must be at least 2 characters long and can only contain lowercase letters, numbers, and underscores (_)',
'Name must be at least 2 characters long, start with a letter, and can only contain lowercase letters, numbers, and underscores (_)',
}
);
export const PACKAGE_NAMES_FETCH_ERROR = i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,23 @@ describe('isValidName', () => {
expect(isValidName('valid_name')).toBe(true);
expect(isValidName('anothervalidname')).toBe(true);
});
it('should return false for names starting with numbers', () => {
expect(isValidName('123name')).toBe(false);
expect(isValidName('1name')).toBe(false);
expect(isValidName('999invalid')).toBe(false);
});

it('should return false for names starting with underscore', () => {
expect(isValidName('_name')).toBe(true);
expect(isValidName('_invalid_name')).toBe(true);
expect(isValidName('__name')).toBe(true);
});

it('should return true for names starting with letters followed by numbers', () => {
expect(isValidName('name123')).toBe(true);
expect(isValidName('valid1')).toBe(true);
expect(isValidName('valid_123')).toBe(true);
});

it('should return false for empty string', () => {
expect(isValidName('')).toBe(false);
Expand Down