forked from redhat-developer/vscode-openshift-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"Create Component from Git" doesn't sanitize the suggested component …
…name redhat-developer#3294 Fixes: redhat-developer#3294 Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
- Loading branch information
Showing
3 changed files
with
29 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
|
||
/** | ||
* Builds a sanitized compponent name from a component folder full path or | ||
* a Git-repo URL | ||
* | ||
* @param pathOrURL an absolute path ot a Git-repo URL | ||
* @returns sanitized component name | ||
*/ | ||
export function buildSanitizedComponentName(pathOrURL?: string): string { | ||
let folder: string = pathOrURL ? pathOrURL : ''; | ||
folder = folder.endsWith('.git') ? folder.substring(0, folder.lastIndexOf('.git')) : folder; | ||
const isWindowsPath = folder.length > 1 && folder.charAt(1) === ':'; | ||
const componentNameFromFolder = folder // | ||
.substring(folder.lastIndexOf(isWindowsPath ? '\\' : '/') + 1) | ||
.toLocaleLowerCase() | ||
.replace(/[^a-z0-9-]+/g, '-') | ||
.replace(/-+/g, '-') | ||
.replace(/-$/, '') | ||
.replace(/^[0-9]+/, ''); | ||
return componentNameFromFolder.length ? componentNameFromFolder : 'component'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters