Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
3e0ded9c
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3e0ded9c
编写于
10月 22, 2019
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
keep input (for toString) when using URI.parse, URI.file uses now URI.parse
Add tests that check our logic against Nodejs's pathToFileURL
上级
359c17a6
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
65 addition
and
21 deletion
+65
-21
src/vs/base/common/uri.ts
src/vs/base/common/uri.ts
+34
-8
src/vs/base/test/node/uri.test.ts
src/vs/base/test/node/uri.test.ts
+31
-13
未找到文件。
src/vs/base/common/uri.ts
浏览文件 @
3e0ded9c
...
@@ -74,8 +74,17 @@ function _referenceResolution(scheme: string, path: string): string {
...
@@ -74,8 +74,17 @@ function _referenceResolution(scheme: string, path: string): string {
const
_empty
=
''
;
const
_empty
=
''
;
const
_slash
=
'
/
'
;
const
_slash
=
'
/
'
;
const
_regexp
=
/^
(([^
:
/
?#
]
+
?)
:
)?(\/\/([^/
?#
]
*
))?([^
?#
]
*
)(\?([^
#
]
*
))?(
#
(
.*
))?
/
;
const
_regexp
=
/^
(([^
:
/
?#
]
+
?)
:
)?(\/\/([^/
?#
]
*
))?([^
?#
]
*
)(\?([^
#
]
*
))?(
#
(
.*
))?
/
;
const
enum
MatchIndex
{
scheme
=
2
,
authority
=
4
,
path
=
5
,
query
=
7
,
fragment
=
9
}
/**
/**
* Uniform Resource Identifier (URI) http://tools.ietf.org/html/rfc3986.
* Uniform Resource Identifier (URI) http://tools.ietf.org/html/rfc3986.
* This class is a simple parser which creates the basic component parts
* This class is a simple parser which creates the basic component parts
...
@@ -262,15 +271,24 @@ export class URI implements UriComponents {
...
@@ -262,15 +271,24 @@ export class URI implements UriComponents {
static
parse
(
value
:
string
):
URI
{
static
parse
(
value
:
string
):
URI
{
const
match
=
_regexp
.
exec
(
value
);
const
match
=
_regexp
.
exec
(
value
);
if
(
!
match
)
{
if
(
!
match
)
{
return
new
_URI
(
_empty
,
_empty
,
_empty
,
_empty
,
_empty
);
throw
new
Error
(
`[UriError]: Invalid input:
${
value
}
`
);
}
}
return
new
_URI
(
match
[
2
]
||
_empty
,
const
scheme
=
_schemeFix
(
match
[
MatchIndex
.
scheme
])
||
_empty
;
percentDecode
(
match
[
4
]
||
_empty
),
const
authority
=
match
[
MatchIndex
.
authority
]
||
_empty
;
percentDecode
(
match
[
5
]
||
_empty
),
const
path
=
_referenceResolution
(
scheme
,
match
[
MatchIndex
.
path
]
||
_empty
);
percentDecode
(
match
[
7
]
||
_empty
),
const
query
=
match
[
MatchIndex
.
query
]
||
_empty
;
percentDecode
(
match
[
9
]
||
_empty
)
const
fragment
=
match
[
MatchIndex
.
fragment
]
||
_empty
;
const
result
=
new
_URI
(
scheme
,
percentDecode
(
authority
),
percentDecode
(
path
),
percentDecode
(
query
),
percentDecode
(
fragment
),
);
);
result
.
_formatted
=
_toString
(
false
,
scheme
,
authority
,
path
,
query
,
fragment
);
return
result
;
}
}
/**
/**
...
@@ -318,7 +336,15 @@ export class URI implements UriComponents {
...
@@ -318,7 +336,15 @@ export class URI implements UriComponents {
}
}
}
}
return
new
_URI
(
'
file
'
,
authority
,
path
,
_empty
,
_empty
);
if
(
path
.
charAt
(
0
)
!==
_slash
)
{
path
=
_slash
+
path
;
}
// escape some vital characters
authority
=
authority
.
replace
(
/%/g
,
'
%25
'
);
path
=
path
.
replace
(
/%/g
,
'
%25
'
);
return
URI
.
parse
(
'
file://
'
+
authority
+
path
);
}
}
static
from
(
components
:
{
scheme
:
string
;
authority
?:
string
;
path
?:
string
;
query
?:
string
;
fragment
?:
string
;
}):
URI
{
static
from
(
components
:
{
scheme
:
string
;
authority
?:
string
;
path
?:
string
;
query
?:
string
;
fragment
?:
string
;
}):
URI
{
...
...
src/vs/base/test/
common
/uri.test.ts
→
src/vs/base/test/
node
/uri.test.ts
浏览文件 @
3e0ded9c
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
import
*
as
assert
from
'
assert
'
;
import
*
as
assert
from
'
assert
'
;
import
{
URI
,
UriComponents
}
from
'
vs/base/common/uri
'
;
import
{
URI
,
UriComponents
}
from
'
vs/base/common/uri
'
;
import
{
isWindows
}
from
'
vs/base/common/platform
'
;
import
{
isWindows
}
from
'
vs/base/common/platform
'
;
import
{
pathToFileURL
}
from
'
url
'
;
suite
(
'
URI
'
,
()
=>
{
suite
(
'
URI
'
,
()
=>
{
test
(
'
file#toString
'
,
()
=>
{
test
(
'
file#toString
'
,
()
=>
{
...
@@ -427,21 +427,24 @@ suite('URI', () => {
...
@@ -427,21 +427,24 @@ suite('URI', () => {
});
});
test
(
'
Unable to open
\'
%A0.txt
\'
: URI malformed #76506
'
,
function
()
{
test
(
'
Unable to open
\'
%A0.txt
\'
: URI malformed #76506
'
,
function
()
{
let
uriFromPath
=
URI
.
file
(
'
/foo/%A0.txt
'
);
let
uri
=
URI
.
file
(
'
/foo/%A0.txt
'
);
let
uriFromStr
=
URI
.
parse
(
uriFromPath
.
toString
());
let
uri2
=
URI
.
parse
(
uri
.
toString
());
assert
.
equal
(
uriFromPath
.
scheme
,
uriFromStr
.
scheme
);
assert
.
equal
(
uri
.
scheme
,
uri2
.
scheme
);
assert
.
equal
(
uriFromPath
.
path
,
uriFromStr
.
path
);
assert
.
equal
(
uri
.
path
,
uri2
.
path
);
assert
.
equal
(
uriFromPath
.
toString
(),
'
file:///foo/%25A0.txt
'
);
assert
.
equal
(
uriFromStr
.
toString
(),
'
file:///foo/%25A0.txt
'
);
uri
=
URI
.
file
(
'
/foo/%2e.txt
'
);
uri2
=
URI
.
parse
(
uri
.
toString
());
assert
.
equal
(
uri
.
scheme
,
uri2
.
scheme
);
assert
.
equal
(
uri
.
path
,
uri2
.
path
);
});
});
test
(
'
Valid percent-encoded character in filename
'
,
function
()
{
let
uriFromPath
=
URI
.
file
(
'
/foo/%2e.txt
'
);
let
uriFromStr
=
URI
.
parse
(
uriFromPath
.
toString
());
assert
.
equal
(
uriFromPath
.
scheme
,
uriFromStr
.
scheme
);
assert
.
equal
(
uriFromPath
.
path
,
uriFromStr
.
path
);
assert
.
equal
(
uriFromPath
.
toString
(),
'
file:///foo/%252e.txt
'
);
assert
.
equal
(
uriFromStr
.
toString
(),
'
file:///foo/%252e.txt
'
);
});
test
(
'
Links in markdown are broken if url contains encoded parameters #79474
'
,
function
()
{
test
(
'
Links in markdown are broken if url contains encoded parameters #79474
'
,
function
()
{
this
.
skip
();
let
strIn
=
'
https://myhost.com/Redirect?url=http%3A%2F%2Fwww.bing.com%3Fsearch%3Dtom
'
;
let
strIn
=
'
https://myhost.com/Redirect?url=http%3A%2F%2Fwww.bing.com%3Fsearch%3Dtom
'
;
let
uri1
=
URI
.
parse
(
strIn
);
let
uri1
=
URI
.
parse
(
strIn
);
let
strOut
=
uri1
.
toString
();
let
strOut
=
uri1
.
toString
();
...
@@ -456,7 +459,6 @@ suite('URI', () => {
...
@@ -456,7 +459,6 @@ suite('URI', () => {
});
});
test
(
'
Uri#parse can break path-component #45515
'
,
function
()
{
test
(
'
Uri#parse can break path-component #45515
'
,
function
()
{
this
.
skip
();
let
strIn
=
'
https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437
'
;
let
strIn
=
'
https://firebasestorage.googleapis.com/v0/b/brewlangerie.appspot.com/o/products%2FzVNZkudXJyq8bPGTXUxx%2FBetterave-Sesame.jpg?alt=media&token=0b2310c4-3ea6-4207-bbde-9c3710ba0437
'
;
let
uri1
=
URI
.
parse
(
strIn
);
let
uri1
=
URI
.
parse
(
strIn
);
let
strOut
=
uri1
.
toString
();
let
strOut
=
uri1
.
toString
();
...
@@ -499,4 +501,20 @@ suite('URI', () => {
...
@@ -499,4 +501,20 @@ suite('URI', () => {
// }
// }
// console.profileEnd();
// console.profileEnd();
});
});
function
assertFileUri
(
path
:
string
):
void
{
// check that our uri aligns with nodejs
const
actual
=
URI
.
file
(
path
).
toString
();
const
expected
=
pathToFileURL
(
path
).
href
;
assert
.
equal
(
actual
,
expected
);
}
test
(
'
URI.file vs pathToFileURL
'
,
function
()
{
assertFileUri
(
'
/foo/bar
'
);
assertFileUri
(
'
/foo/%2e.txt
'
);
// %2e -> .
assertFileUri
(
'
/foo/%A0.txt
'
);
// %A0 -> invalid
assertFileUri
(
'
/foo/ü.txt
'
);
assertFileUri
(
'
/foo/ß.txt
'
);
// assertFileUri('foo'); nodejs resolves the path first
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录