Skip to content

Commit 7703a12

Browse files
committed
Updated REGEX_MODULE_PATH to not allow _ or leading lowercase letters.
1 parent 8094b7b commit 7703a12

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/storage/names.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ export const CLASS_NAME_TELEOP = 'Teleop';
2525
export const JSON_FILE_EXTENSION = '.json';
2626
export const UPLOAD_DOWNLOAD_FILE_EXTENSION = '.blocks';
2727

28-
/**
29-
* Regular expression to extract the project name and the class name from a module path.
30-
*/
31-
const REGEX_MODULE_PATH = '^([A-Za-z_][A-Za-z0-9_]*)/([A-Za-z_][A-Za-z0-9_]*).json$';
28+
const REGEX_PROJECT_OR_CLASS_NAME_PART = '[A-Z][A-Za-z0-9]*';
29+
const REGEX_CLASS_NAME = '^' + REGEX_PROJECT_OR_CLASS_NAME_PART + '$';
30+
const REGEX_MODULE_PATH = '^(' + REGEX_PROJECT_OR_CLASS_NAME_PART + ')/(' +
31+
REGEX_PROJECT_OR_CLASS_NAME_PART + ')' + escapeRegExp(JSON_FILE_EXTENSION) + '$';
3232

3333
/**
3434
* Returns true if the given name is a valid class name.
3535
*/
3636
export function isValidClassName(name: string): boolean {
3737
if (name) {
38-
return /^[A-Z][A-Za-z0-9]*$/.test(name);
38+
return new RegExp(REGEX_CLASS_NAME).test(name);
3939
}
4040
return false;
4141
}
@@ -79,9 +79,8 @@ export function snakeCaseToPascalCase(snakeCaseName: string): string {
7979
* Returns the module path regex pattern for modules in the given project.
8080
*/
8181
export function makeModulePathRegexPattern(projectName: string): string {
82-
const prefix = projectName + '/';
83-
const suffix = JSON_FILE_EXTENSION;
84-
return '^' + escapeRegExp(prefix) + '.*' + escapeRegExp(suffix) + '$';
82+
return '^' + escapeRegExp(projectName) + '/' + REGEX_PROJECT_OR_CLASS_NAME_PART +
83+
escapeRegExp(JSON_FILE_EXTENSION) + '$';
8584
}
8685

8786
function escapeRegExp(text: string): string {

0 commit comments

Comments
 (0)