Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
1603d3e6
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,发现更多精彩内容 >>
提交
1603d3e6
编写于
11月 14, 2019
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
validator must support URI and URL, also extract utils for re-use
上级
d891b0d3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
38 addition
and
40 deletion
+38
-40
src/vs/base/common/resources.ts
src/vs/base/common/resources.ts
+22
-0
src/vs/editor/browser/services/openerService.ts
src/vs/editor/browser/services/openerService.ts
+5
-21
src/vs/editor/contrib/links/getLinks.ts
src/vs/editor/contrib/links/getLinks.ts
+2
-13
src/vs/platform/opener/common/opener.ts
src/vs/platform/opener/common/opener.ts
+1
-1
src/vs/workbench/contrib/url/common/trustedDomainsValidator.ts
...s/workbench/contrib/url/common/trustedDomainsValidator.ts
+8
-5
未找到文件。
src/vs/base/common/resources.ts
浏览文件 @
1603d3e6
...
...
@@ -361,3 +361,25 @@ export function toLocalResource(resource: URI, authority: string | undefined): U
return
resource
.
with
({
scheme
:
Schemas
.
file
});
}
export
function
matchesScheme
(
target
:
URI
|
URL
,
scheme
:
string
)
{
if
(
URI
.
isUri
(
target
))
{
return
equalsIgnoreCase
(
target
.
scheme
,
scheme
);
}
else
{
return
equalsIgnoreCase
(
target
.
protocol
,
scheme
+
'
:
'
);
}
}
/**
* `true` when urls can be constructed via `new URL("string")`, should only be `false` in IE:
* https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#Browser_compatibility
*/
export
const
hasURLCtor
=
(
function
()
{
try
{
// tslint:disable-next-line: no-unused-expression
new
URL
(
'
some://thing
'
);
return
true
;
}
catch
{
return
false
;
}
})();
src/vs/editor/browser/services/openerService.ts
浏览文件 @
1603d3e6
...
...
@@ -8,21 +8,13 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import
{
LinkedList
}
from
'
vs/base/common/linkedList
'
;
import
{
parse
}
from
'
vs/base/common/marshalling
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
*
as
resources
from
'
vs/base/common/resources
'
;
import
{
equalsIgnoreCase
}
from
'
vs/base/common/strings
'
;
import
{
matchesScheme
,
normalizePath
}
from
'
vs/base/common/resources
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
ICodeEditorService
}
from
'
vs/editor/browser/services/codeEditorService
'
;
import
{
CommandsRegistry
,
ICommandService
}
from
'
vs/platform/commands/common/commands
'
;
import
{
IOpener
,
IOpenerService
,
IValidator
,
IExternalUriResolver
,
OpenOptions
,
ResolveExternalUriOptions
,
IResolvedExternalUri
,
IExternalOpener
}
from
'
vs/platform/opener/common/opener
'
;
import
{
EditorOpenContext
}
from
'
vs/platform/editor/common/editor
'
;
function
hasScheme
(
target
:
URI
|
URL
,
scheme
:
string
)
{
if
(
URI
.
isUri
(
target
))
{
return
equalsIgnoreCase
(
target
.
scheme
,
scheme
);
}
else
{
return
equalsIgnoreCase
(
target
.
protocol
,
scheme
+
'
:
'
);
}
}
export
class
OpenerService
implements
IOpenerService
{
...
...
@@ -52,7 +44,7 @@ export class OpenerService implements IOpenerService {
// Default opener: maito, http(s), command, and catch-all-editors
this
.
_openerAsExternal
=
{
open
:
async
(
target
:
URI
|
URL
,
options
?:
OpenOptions
)
=>
{
if
(
options
?.
openExternal
||
hasScheme
(
target
,
Schemas
.
mailto
)
||
hasScheme
(
target
,
Schemas
.
http
)
||
ha
sScheme
(
target
,
Schemas
.
https
))
{
if
(
options
?.
openExternal
||
matchesScheme
(
target
,
Schemas
.
mailto
)
||
matchesScheme
(
target
,
Schemas
.
http
)
||
matche
sScheme
(
target
,
Schemas
.
https
))
{
// open externally
await
this
.
_doOpenExternal
(
target
,
options
);
return
true
;
...
...
@@ -63,7 +55,7 @@ export class OpenerService implements IOpenerService {
this
.
_openerAsCommand
=
{
open
:
async
(
target
)
=>
{
if
(
!
ha
sScheme
(
target
,
Schemas
.
command
))
{
if
(
!
matche
sScheme
(
target
,
Schemas
.
command
))
{
return
false
;
}
// run command or bail out if command isn't known
...
...
@@ -107,7 +99,7 @@ export class OpenerService implements IOpenerService {
}
if
(
target
.
scheme
===
Schemas
.
file
)
{
target
=
resources
.
normalizePath
(
target
);
// workaround for non-normalized paths (https://github.com/Microsoft/vscode/issues/12954)
target
=
normalizePath
(
target
);
// workaround for non-normalized paths (https://github.com/Microsoft/vscode/issues/12954)
}
await
editorService
.
openCodeEditor
(
...
...
@@ -142,17 +134,9 @@ export class OpenerService implements IOpenerService {
async
open
(
target
:
URI
|
URL
,
options
?:
OpenOptions
):
Promise
<
boolean
>
{
const
resource
=
URI
.
isUri
(
target
)
?
target
:
URI
.
from
(
target
);
// no scheme ?!?
if
(
!
resource
.
scheme
)
{
return
Promise
.
resolve
(
false
);
}
//todo@joh adopt validator
// check with contributed validators
for
(
const
validator
of
this
.
_validators
.
toArray
())
{
if
(
!
(
await
validator
.
shouldOpen
(
resource
)))
{
if
(
!
(
await
validator
.
shouldOpen
(
target
)))
{
return
false
;
}
}
...
...
src/vs/editor/contrib/links/getLinks.ts
浏览文件 @
1603d3e6
...
...
@@ -13,18 +13,7 @@ import { IModelService } from 'vs/editor/common/services/modelService';
import
{
CommandsRegistry
}
from
'
vs/platform/commands/common/commands
'
;
import
{
isDisposable
,
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
coalesce
}
from
'
vs/base/common/arrays
'
;
// in IE11 there is URL but a constructor
// https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#Browser_compatibility
const
canUseUrl
=
(
function
()
{
try
{
// tslint:disable-next-line: no-unused-expression
new
URL
(
'
some://thing
'
);
return
true
;
}
catch
{
return
false
;
}
})();
import
{
hasURLCtor
}
from
'
vs/base/common/resources
'
;
export
class
Link
implements
ILink
{
...
...
@@ -61,7 +50,7 @@ export class Link implements ILink {
try
{
if
(
URI
.
isUri
(
this
.
_link
.
url
))
{
return
this
.
_link
.
url
;
}
else
if
(
!
canUseUrl
)
{
}
else
if
(
!
hasURLCtor
)
{
return
URI
.
parse
(
this
.
_link
.
url
);
}
else
{
return
new
URL
(
this
.
_link
.
url
);
...
...
src/vs/platform/opener/common/opener.ts
浏览文件 @
1603d3e6
...
...
@@ -43,7 +43,7 @@ export interface IExternalOpener {
}
export
interface
IValidator
{
shouldOpen
(
resource
:
URI
):
Promise
<
boolean
>
;
shouldOpen
(
resource
:
URI
|
URL
):
Promise
<
boolean
>
;
}
export
interface
IExternalUriResolver
{
...
...
src/vs/workbench/contrib/url/common/trustedDomainsValidator.ts
浏览文件 @
1603d3e6
...
...
@@ -5,7 +5,6 @@
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
Severity
from
'
vs/base/common/severity
'
;
import
{
equalsIgnoreCase
}
from
'
vs/base/common/strings
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
IDialogService
}
from
'
vs/platform/dialogs/common/dialogs
'
;
...
...
@@ -20,6 +19,7 @@ import {
}
from
'
vs/workbench/contrib/url/common/trustedDomains
'
;
import
{
IEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IClipboardService
}
from
'
vs/platform/clipboard/common/clipboardService
'
;
import
{
matchesScheme
}
from
'
vs/base/common/resources
'
;
export
class
OpenerValidatorContributions
implements
IWorkbenchContribution
{
constructor
(
...
...
@@ -34,13 +34,16 @@ export class OpenerValidatorContributions implements IWorkbenchContribution {
this
.
_openerService
.
registerValidator
({
shouldOpen
:
r
=>
this
.
validateLink
(
r
)
});
}
async
validateLink
(
resource
:
URI
):
Promise
<
boolean
>
{
const
{
scheme
,
authority
,
path
,
query
,
fragment
}
=
resource
;
if
(
!
equalsIgnoreCase
(
scheme
,
Schemas
.
http
)
&&
!
equalsIgnoreCase
(
scheme
,
Schemas
.
https
))
{
async
validateLink
(
resource
:
URI
|
URL
):
Promise
<
boolean
>
{
if
(
!
matchesScheme
(
resource
,
Schemas
.
http
)
&&
!
matchesScheme
(
resource
,
Schemas
.
https
))
{
return
true
;
}
if
(
!
URI
.
isUri
(
resource
))
{
resource
=
URI
.
from
(
resource
);
}
const
{
scheme
,
authority
,
path
,
query
,
fragment
}
=
resource
;
const
domainToOpen
=
`
${
scheme
}
://
${
authority
}
`
;
const
{
defaultTrustedDomains
,
trustedDomains
}
=
readTrustedDomains
(
this
.
_storageService
,
this
.
_productService
);
const
allTrustedDomains
=
[...
defaultTrustedDomains
,
...
trustedDomains
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录