@@ -26,6 +26,7 @@ import { equalsIgnoreCase, format, startsWithIgnoreCase } from 'vs/base/common/s
2626import { OpenLocalFileAction , OpenLocalFileFolderAction , OpenLocalFolderAction } from 'vs/workbench/browser/actions/workspaceActions' ;
2727import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
2828import { IRemoteAgentEnvironment } from 'vs/platform/remote/common/remoteAgentEnvironment' ;
29+ import { isValidBasename } from 'vs/base/common/extpath' ;
2930import { RemoteFileDialogContext } from 'vs/workbench/browser/contextkeys' ;
3031
3132interface FileQuickPickItem extends IQuickPickItem {
@@ -40,11 +41,6 @@ enum UpdateResult {
4041 InvalidPath
4142}
4243
43- // Reference: https://en.wikipedia.org/wiki/Filename
44- const WINDOWS_INVALID_FILE_CHARS = / [ \\ / : \* \? " < > \| ] / g;
45- const UNIX_INVALID_FILE_CHARS = / [ \\ / ] / g;
46- const WINDOWS_FORBIDDEN_NAMES = / ^ ( c o n | p r n | a u x | c l o c k \$ | n u l | l p t [ 0 - 9 ] | c o m [ 0 - 9 ] ) $ / i;
47-
4844export class RemoteFileDialog {
4945 private options : IOpenDialogOptions ;
5046 private currentFolder : URI ;
@@ -618,7 +614,7 @@ export class RemoteFileDialog {
618614 // Show a yes/no prompt
619615 const message = nls . localize ( 'remoteFileDialog.validateExisting' , '{0} already exists. Are you sure you want to overwrite it?' , resources . basename ( uri ) ) ;
620616 return this . yesNoPrompt ( uri , message ) ;
621- } else if ( ! ( await this . isValidBaseName ( resources . basename ( uri ) ) ) ) {
617+ } else if ( ! ( isValidBasename ( resources . basename ( uri ) , await this . isWindowsOS ( ) ) ) ) {
622618 // Filename not allowed
623619 this . filePickBox . validationMessage = nls . localize ( 'remoteFileDialog.validateBadFilename' , 'Please enter a valid file name.' ) ;
624620 return Promise . resolve ( false ) ;
@@ -712,37 +708,6 @@ export class RemoteFileDialog {
712708 return isWindowsOS ;
713709 }
714710
715- private async isValidBaseName ( name : string ) : Promise < boolean > {
716- if ( ! name || name . length === 0 || / ^ \s + $ / . test ( name ) ) {
717- return false ; // require a name that is not just whitespace
718- }
719-
720- const isWindowsOS = await this . isWindowsOS ( ) ;
721- const INVALID_FILE_CHARS = isWindowsOS ? WINDOWS_INVALID_FILE_CHARS : UNIX_INVALID_FILE_CHARS ;
722- INVALID_FILE_CHARS . lastIndex = 0 ; // the holy grail of software development
723- if ( INVALID_FILE_CHARS . test ( name ) ) {
724- return false ; // check for certain invalid file characters
725- }
726-
727- if ( isWindowsOS && WINDOWS_FORBIDDEN_NAMES . test ( name ) ) {
728- return false ; // check for certain invalid file names
729- }
730-
731- if ( name === '.' || name === '..' ) {
732- return false ; // check for reserved values
733- }
734-
735- if ( isWindowsOS && name [ name . length - 1 ] === '.' ) {
736- return false ; // Windows: file cannot end with a "."
737- }
738-
739- if ( isWindowsOS && name . length !== name . trim ( ) . length ) {
740- return false ; // Windows: file cannot end with a whitespace
741- }
742-
743- return true ;
744- }
745-
746711 private endsWithSlash ( s : string ) {
747712 return / [ \/ \\ ] $ / . test ( s ) ;
748713 }
0 commit comments