Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions Composer/packages/client/__tests__/constants.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { dialogNameRegex } from '../src/constants';

describe('check dialog name', () => {
it('don not support special characters', () => {
expect(dialogNameRegex.test('*a')).toBeFalsy();
expect(dialogNameRegex.test('c*a')).toBeFalsy();
expect(dialogNameRegex.test('c a')).toBeFalsy();
});

it('don not support number at the beginning.', () => {
expect(dialogNameRegex.test('1a')).toBeFalsy();
expect(dialogNameRegex.test('a1')).toBeTruthy();
});
});
2 changes: 2 additions & 0 deletions Composer/packages/client/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ export const QnABotTemplateId = 'QnASample';

export const nameRegex = /^[a-zA-Z0-9-_]+$/;

export const dialogNameRegex = /^[a-zA-Z][a-zA-Z0-9-_]*$/;

export const triggerNotSupportedWarning = formatMessage(
'This trigger type is not supported by the RegEx recognizer. To ensure this trigger is fired, change the recognizer type.'
);
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { RecognizerSchema, useRecognizerConfig, useShellApi } from '@bfc/extensi
import { DialogFactory, SDKKinds } from '@bfc/shared';
import { DialogWrapper, DialogTypes } from '@bfc/ui-shared';

import { DialogCreationCopy, nameRegex } from '../../constants';
import { DialogCreationCopy, dialogNameRegex } from '../../constants';
import { StorageFolder } from '../../recoilModel/types';
import { FieldConfig, useForm } from '../../hooks/useForm';
import { actionsSeedState, schemasState, validateDialogSelectorFamily } from '../../recoilModel';
Expand Down Expand Up @@ -46,8 +46,10 @@ export const CreateDialogModal: React.FC<CreateDialogModalProps> = (props) => {
name: {
required: true,
validate: (value) => {
if (!nameRegex.test(value)) {
return formatMessage('Spaces and special characters are not allowed. Use letters, numbers, -, or _.');
if (!dialogNameRegex.test(value)) {
return formatMessage(
"Spaces and special characters are not allowed. Use letters, numbers, -, or _ and don't use number at the beginning."
);
}
if (dialogs.some((dialog) => dialog.id.toLowerCase() === value.toLowerCase())) {
return formatMessage('Duplicate dialog name');
Expand Down