Fix for user using command palette (#18948)

* fix for user using command palette command

* rework if a user uses the create azure function via the command

* for now only show in vs code

* move logic to azureFunctionService + address comments

* fix command location

* address comments

* fix validateFunction
This commit is contained in:
Vasu Bhog
2022-04-08 10:28:45 -07:00
committed by GitHub
parent dc14201088
commit ed8d2f9927
5 changed files with 142 additions and 42 deletions

View File

@@ -10,6 +10,7 @@ import * as fs from 'fs';
import * as path from 'path';
import * as glob from 'fast-glob';
import * as cp from 'child_process';
import * as constants from '../common/constants';
export interface ValidationResult {
errorMessage: string;
@@ -162,6 +163,30 @@ export function escapeClosingBrackets(str: string): string {
return str.replace(']', ']]');
}
/**
* Removes all special characters from object name
* @param objectName can include brackets/periods and user entered special characters
* @returns the object name without any special characters
*/
export function santizeObjectName(objectName: string): string {
return objectName.replace(/[^a-zA-Z0-9 ]/g, '');
}
/**
* Check to see if the input from user entered is valid
* @param input from user input
* @returns returns error if the input is empty or has special characters, undefined if the input is valid
*/
export function validateFunctionName(input: string): string | undefined {
const specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
if (!input) {
return constants.nameMustNotBeEmpty;
} else if (specialChars.test(input)) {
return constants.hasSpecialCharacters;
}
return undefined;
}
/**
* Gets the package info for the extension based on where the extension is installed
* @returns the package info object