Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
bcd81812
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,体验更适合开发者的 AI 搜索 >>
提交
bcd81812
编写于
9月 15, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more strict (and correct) URI.file, #34449
上级
bedd750b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
23 deletion
+36
-23
src/vs/base/common/uri.ts
src/vs/base/common/uri.ts
+11
-4
src/vs/base/test/common/uri.test.ts
src/vs/base/test/common/uri.test.ts
+25
-19
未找到文件。
src/vs/base/common/uri.ts
浏览文件 @
bcd81812
...
...
@@ -56,6 +56,7 @@ export default class URI {
private
static
_empty
=
''
;
private
static
_slash
=
'
/
'
;
private
static
_regexp
=
/^
(([^
:
/
?#
]
+
?)
:
)?(\/\/([^/
?#
]
*
))?([^
?#
]
*
)(\?([^
#
]
*
))?(
#
(
.*
))?
/
;
private
static
_driveLetter
=
/^
[
a-zA-Z
]
:/
;
private
static
_driveLetterPath
=
/^
\/[
a-zA-Z
]
:/
;
private
static
_upperCaseDrive
=
/^
(\/)?([
A-Z
]
:
)
/
;
...
...
@@ -212,19 +213,25 @@ export default class URI {
let
idx
=
path
.
indexOf
(
URI
.
_slash
,
2
);
if
(
idx
===
-
1
)
{
authority
=
path
.
substring
(
2
);
path
=
URI
.
_
empty
;
path
=
URI
.
_
slash
;
}
else
{
authority
=
path
.
substring
(
2
,
idx
);
path
=
path
.
substring
(
idx
);
}
}
// Ensure that path starts with a slash
// or that it is at least a slash
if
(
path
[
0
]
!==
URI
.
_slash
)
{
// absolute windows paths get another slash
if
(
URI
.
_driveLetter
.
test
(
path
))
{
path
=
URI
.
_slash
+
path
;
}
// path must be absolute because we cannot format them
// otherwise: `file:./foo` -> file://./foo -> `{ authority: '.', path: 'foo' }`
// https://tools.ietf.org/html/rfc8089#section-2
else
if
(
path
[
0
]
!==
URI
.
_slash
)
{
throw
new
Error
(
'
[UriError]: relative paths are not supported.
'
);
}
return
new
URI
(
'
file
'
,
authority
,
path
,
URI
.
_empty
,
URI
.
_empty
);
}
...
...
src/vs/base/test/common/uri.test.ts
浏览文件 @
bcd81812
...
...
@@ -38,13 +38,11 @@ suite('URI', () => {
assert
.
equal
(
URI
.
file
(
'
c:/win/path/
'
).
fsPath
,
'
c:
\\
win
\\
path
\\
'
);
assert
.
equal
(
URI
.
file
(
'
C:/win/path
'
).
fsPath
,
'
c:
\\
win
\\
path
'
);
assert
.
equal
(
URI
.
file
(
'
/c:/win/path
'
).
fsPath
,
'
c:
\\
win
\\
path
'
);
assert
.
equal
(
URI
.
file
(
'
./c/win/path
'
).
fsPath
,
'
\\
.
\\
c
\\
win
\\
path
'
);
}
else
{
assert
.
equal
(
URI
.
file
(
'
c:/win/path
'
).
fsPath
,
'
c:/win/path
'
);
assert
.
equal
(
URI
.
file
(
'
c:/win/path/
'
).
fsPath
,
'
c:/win/path/
'
);
assert
.
equal
(
URI
.
file
(
'
C:/win/path
'
).
fsPath
,
'
c:/win/path
'
);
assert
.
equal
(
URI
.
file
(
'
/c:/win/path
'
).
fsPath
,
'
c:/win/path
'
);
assert
.
equal
(
URI
.
file
(
'
./c/win/path
'
).
fsPath
,
'
/./c/win/path
'
);
}
});
...
...
@@ -318,27 +316,12 @@ suite('URI', () => {
test
(
'
URI#file, no path-is-uri check
'
,
()
=>
{
// we don't complain here
let
value
=
URI
.
file
(
'
file://path/to/file
'
);
let
value
=
URI
.
file
(
'
/
file://path/to/file
'
);
assert
.
equal
(
value
.
scheme
,
'
file
'
);
assert
.
equal
(
value
.
authority
,
''
);
assert
.
equal
(
value
.
path
,
'
/file://path/to/file
'
);
});
test
(
'
URI#file, always slash
'
,
()
=>
{
var
value
=
URI
.
file
(
'
a.file
'
);
assert
.
equal
(
value
.
scheme
,
'
file
'
);
assert
.
equal
(
value
.
authority
,
''
);
assert
.
equal
(
value
.
path
,
'
/a.file
'
);
assert
.
equal
(
value
.
toString
(),
'
file:///a.file
'
);
value
=
URI
.
parse
(
value
.
toString
());
assert
.
equal
(
value
.
scheme
,
'
file
'
);
assert
.
equal
(
value
.
authority
,
''
);
assert
.
equal
(
value
.
path
,
'
/a.file
'
);
assert
.
equal
(
value
.
toString
(),
'
file:///a.file
'
);
});
test
(
'
URI.toString, only scheme and query
'
,
()
=>
{
var
value
=
URI
.
parse
(
'
stuff:?qüery
'
);
assert
.
equal
(
value
.
toString
(),
'
stuff:?q%C3%BCery
'
);
...
...
@@ -427,13 +410,36 @@ suite('URI', () => {
assert
.
equal
(
uri
.
toString
(
true
),
'
https://twitter.com/search?src=typd&q=%23tag
'
);
});
test
(
'
class URI cannot represent relative file paths, #34449
'
,
function
()
{
const
uri
=
URI
.
parse
(
'
file:./relative/path
'
);
assert
.
equal
(
uri
.
scheme
,
'
file
'
);
assert
.
equal
(
uri
.
authority
,
''
);
assert
.
equal
(
uri
.
path
,
'
./relative/path
'
);
assert
.
equal
(
uri
.
toString
(),
'
file://./relative/path
'
);
// this is asymetric to be spec-compliant
const
uri2
=
URI
.
parse
(
uri
.
toString
());
assert
.
equal
(
uri2
.
authority
,
'
.
'
);
assert
.
equal
(
uri2
.
path
,
'
/relative/path
'
);
});
test
(
'
class URI cannot represent relative file paths, #34449
'
,
function
()
{
const
path
=
'
/foo/bar
'
;
assert
.
equal
(
URI
.
file
(
path
).
path
,
path
);
// no relative paths
assert
.
throws
(()
=>
URI
.
file
(
'
foo/bar
'
));
assert
.
throws
(()
=>
URI
.
file
(
'
./foo/bar
'
));
});
test
(
'
URI - (de)serialize
'
,
function
()
{
var
values
=
[
URI
.
parse
(
'
http://localhost:8080/far
'
),
URI
.
file
(
'
c:
\\
test with %25
\\
c#code
'
),
URI
.
file
(
'
\\\\
shäres
\\
path
\\
c#
\\
plugin.json
'
),
URI
.
file
(
'
//shäres/path/c#/
plugin.json
'
),
URI
.
parse
(
'
http://api/files/test.me?t=1234
'
),
URI
.
parse
(
'
http://api/files/test.me?t=1234#fff
'
),
URI
.
parse
(
'
http://api/files/test.me#fff
'
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录