Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
9ad8bf66
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9ad8bf66
编写于
4月 25, 2019
作者:
A
Alex Ross
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
File name validation fix in picker
上级
487f095e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
29 addition
and
8 deletion
+29
-8
src/vs/workbench/services/dialogs/browser/remoteFileDialog.ts
...vs/workbench/services/dialogs/browser/remoteFileDialog.ts
+29
-8
未找到文件。
src/vs/workbench/services/dialogs/browser/remoteFileDialog.ts
浏览文件 @
9ad8bf66
...
...
@@ -9,7 +9,7 @@ import * as objects from 'vs/base/common/objects';
import
{
IFileService
,
IFileStat
,
FileKind
}
from
'
vs/platform/files/common/files
'
;
import
{
IQuickInputService
,
IQuickPickItem
,
IQuickPick
}
from
'
vs/platform/quickinput/common/quickInput
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
isWindows
}
from
'
vs/base/common/platform
'
;
import
{
isWindows
,
OperatingSystem
}
from
'
vs/base/common/platform
'
;
import
{
ISaveDialogOptions
,
IOpenDialogOptions
,
IFileDialogService
}
from
'
vs/platform/dialogs/common/dialogs
'
;
import
{
REMOTE_HOST_SCHEME
}
from
'
vs/platform/remote/common/remoteHosts
'
;
import
{
ILabelService
}
from
'
vs/platform/label/common/label
'
;
...
...
@@ -26,6 +26,7 @@ import { RemoteFileDialogContext } from 'vs/workbench/common/contextkeys';
import
{
equalsIgnoreCase
,
format
}
from
'
vs/base/common/strings
'
;
import
{
OpenLocalFileAction
,
OpenLocalFileFolderAction
,
OpenLocalFolderAction
}
from
'
vs/workbench/browser/actions/workspaceActions
'
;
import
{
IKeybindingService
}
from
'
vs/platform/keybinding/common/keybinding
'
;
import
{
IRemoteAgentEnvironment
}
from
'
vs/platform/remote/common/remoteAgentEnvironment
'
;
interface
FileQuickPickItem
extends
IQuickPickItem
{
uri
:
URI
;
...
...
@@ -40,7 +41,8 @@ enum UpdateResult {
}
// Reference: https://en.wikipedia.org/wiki/Filename
const
INVALID_FILE_CHARS
=
isWindows
?
/
[\\/
:
\*\?
"<>
\|]
/g
:
/
[\\/]
/g
;
const
WINDOWS_INVALID_FILE_CHARS
=
/
[\\/
:
\*\?
"<>
\|]
/g
;
const
UNIX_INVALID_FILE_CHARS
=
/
[\\/]
/g
;
const
WINDOWS_FORBIDDEN_NAMES
=
/^
(
con|prn|aux|clock
\$
|nul|lpt
[
0-9
]
|com
[
0-9
])
$/i
;
export
class
RemoteFileDialog
{
...
...
@@ -60,6 +62,7 @@ export class RemoteFileDialog {
private
activeItem
:
FileQuickPickItem
;
private
userHome
:
URI
;
private
badPath
:
string
|
undefined
;
private
remoteAgentEnvironment
:
IRemoteAgentEnvironment
|
null
;
constructor
(
@
IFileService
private
readonly
fileService
:
IFileService
,
...
...
@@ -136,9 +139,16 @@ export class RemoteFileDialog {
return
defaultUri
?
defaultUri
.
scheme
:
(
available
?
available
[
0
]
:
Schemas
.
file
);
}
private
async
getRemoteAgentEnvironment
():
Promise
<
IRemoteAgentEnvironment
|
null
>
{
if
(
this
.
remoteAgentEnvironment
===
undefined
)
{
this
.
remoteAgentEnvironment
=
await
this
.
remoteAgentService
.
getEnvironment
();
}
return
this
.
remoteAgentEnvironment
;
}
private
async
getUserHome
():
Promise
<
URI
>
{
if
(
this
.
scheme
!==
Schemas
.
file
)
{
const
env
=
await
this
.
remoteAgentService
.
ge
tEnvironment
();
const
env
=
await
this
.
getRemoteAgen
tEnvironment
();
if
(
env
)
{
return
env
.
userHome
;
}
...
...
@@ -585,7 +595,7 @@ export class RemoteFileDialog {
// Show a yes/no prompt
const
message
=
nls
.
localize
(
'
remoteFileDialog.validateExisting
'
,
'
{0} already exists. Are you sure you want to overwrite it?
'
,
resources
.
basename
(
uri
));
return
this
.
yesNoPrompt
(
uri
,
message
);
}
else
if
(
!
this
.
isValidBaseName
(
resources
.
basename
(
uri
)))
{
}
else
if
(
!
(
await
this
.
isValidBaseName
(
resources
.
basename
(
uri
)
)))
{
// Filename not allowed
this
.
filePickBox
.
validationMessage
=
nls
.
localize
(
'
remoteFileDialog.validateBadFilename
'
,
'
Please enter a valid file name.
'
);
return
Promise
.
resolve
(
false
);
...
...
@@ -664,17 +674,28 @@ export class RemoteFileDialog {
}
}
private
isValidBaseName
(
name
:
string
):
boolean
{
private
async
isWindowsOS
():
Promise
<
boolean
>
{
let
isWindowsOS
=
isWindows
;
const
env
=
await
this
.
getRemoteAgentEnvironment
();
if
(
env
)
{
isWindowsOS
=
env
.
os
===
OperatingSystem
.
Windows
;
}
return
isWindowsOS
;
}
private
async
isValidBaseName
(
name
:
string
):
Promise
<
boolean
>
{
if
(
!
name
||
name
.
length
===
0
||
/^
\s
+$/
.
test
(
name
))
{
return
false
;
// require a name that is not just whitespace
}
const
isWindowsOS
=
await
this
.
isWindowsOS
();
const
INVALID_FILE_CHARS
=
isWindowsOS
?
WINDOWS_INVALID_FILE_CHARS
:
UNIX_INVALID_FILE_CHARS
;
INVALID_FILE_CHARS
.
lastIndex
=
0
;
// the holy grail of software development
if
(
INVALID_FILE_CHARS
.
test
(
name
))
{
return
false
;
// check for certain invalid file characters
}
if
(
isWindows
&&
WINDOWS_FORBIDDEN_NAMES
.
test
(
name
))
{
if
(
isWindows
OS
&&
WINDOWS_FORBIDDEN_NAMES
.
test
(
name
))
{
return
false
;
// check for certain invalid file names
}
...
...
@@ -682,11 +703,11 @@ export class RemoteFileDialog {
return
false
;
// check for reserved values
}
if
(
isWindows
&&
name
[
name
.
length
-
1
]
===
'
.
'
)
{
if
(
isWindows
OS
&&
name
[
name
.
length
-
1
]
===
'
.
'
)
{
return
false
;
// Windows: file cannot end with a "."
}
if
(
isWindows
&&
name
.
length
!==
name
.
trim
().
length
)
{
if
(
isWindows
OS
&&
name
.
length
!==
name
.
trim
().
length
)
{
return
false
;
// Windows: file cannot end with a whitespace
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录