Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
cab4b64a
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,发现更多精彩内容 >>
提交
cab4b64a
编写于
6月 01, 2018
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implement encodeURIComponentFast, #50800
上级
01d022a4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
123 addition
and
47 deletion
+123
-47
src/vs/base/common/uri.ts
src/vs/base/common/uri.ts
+123
-47
未找到文件。
src/vs/base/common/uri.ts
浏览文件 @
cab4b64a
...
...
@@ -5,21 +5,7 @@
'
use strict
'
;
import
*
as
platform
from
'
vs/base/common/platform
'
;
function
_encode
(
ch
:
string
):
string
{
return
'
%
'
+
ch
.
charCodeAt
(
0
).
toString
(
16
).
toUpperCase
();
}
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
function
encodeURIComponent2
(
str
:
string
):
string
{
return
encodeURIComponent
(
str
).
replace
(
/
[
!'()*
]
/g
,
_encode
);
}
function
encodeNoop
(
str
:
string
):
string
{
return
str
.
replace
(
/
[
#?
]
/
,
_encode
);
}
import
{
CharCode
}
from
'
vs/base/common/charCode
'
;
const
_schemePattern
=
/^
\w[\w\d
+.-
]
*$/
;
const
_singleSlashStart
=
/^
\/
/
;
...
...
@@ -75,7 +61,6 @@ const _empty = '';
const
_slash
=
'
/
'
;
const
_regexp
=
/^
(([^
:
/
?#
]
+
?)
:
)?(\/\/([^/
?#
]
*
))?([^
?#
]
*
)(\?([^
#
]
*
))?(
#
(
.*
))?
/
;
const
_driveLetterPath
=
/^
\/[
a-zA-Z
]
:/
;
const
_upperCaseDrive
=
/^
(\/)?([
A-Z
]
:
)
/
;
/**
* Uniform Resource Identifier (URI) http://tools.ietf.org/html/rfc3986.
...
...
@@ -378,6 +363,109 @@ class _URI extends URI {
}
}
// reserved characters: https://tools.ietf.org/html/rfc3986#section-2.2
const
encodeTable
=
{
[
CharCode
.
Colon
]:
'
%3A
'
,
// gen-delims
[
CharCode
.
Slash
]:
'
%2F
'
,
[
CharCode
.
QuestionMark
]:
'
%3F
'
,
[
CharCode
.
Hash
]:
'
%23
'
,
[
CharCode
.
OpenSquareBracket
]:
'
%5B
'
,
[
CharCode
.
CloseSquareBracket
]:
'
%5D
'
,
[
CharCode
.
AtSign
]:
'
%40
'
,
[
CharCode
.
ExclamationMark
]:
'
%21
'
,
// sub-delims
[
CharCode
.
DollarSign
]:
'
%24
'
,
[
CharCode
.
Ampersand
]:
'
%26
'
,
[
CharCode
.
SingleQuote
]:
'
%27
'
,
[
CharCode
.
OpenParen
]:
'
%28
'
,
[
CharCode
.
CloseParen
]:
'
%29
'
,
[
CharCode
.
Asterisk
]:
'
%2A
'
,
[
CharCode
.
Plus
]:
'
%2B
'
,
[
CharCode
.
Comma
]:
'
%2C
'
,
[
CharCode
.
Semicolon
]:
'
%3B
'
,
[
CharCode
.
Equals
]:
'
%3D
'
,
[
CharCode
.
Space
]:
'
%20
'
,
};
function
encodeURIComponentFast
(
uriComponent
:
string
,
allowSlash
:
boolean
):
string
{
let
res
:
string
=
undefined
;
let
nativeEncodePos
=
-
1
;
for
(
let
pos
=
0
;
pos
<
uriComponent
.
length
;
pos
++
)
{
let
code
=
uriComponent
.
charCodeAt
(
pos
);
// unreserved characters: https://tools.ietf.org/html/rfc3986#section-2.3
if
(
(
code
>=
CharCode
.
a
&&
code
<=
CharCode
.
z
)
||
(
code
>=
CharCode
.
A
&&
code
<=
CharCode
.
Z
)
||
(
code
>=
CharCode
.
Digit0
&&
code
<=
CharCode
.
Digit9
)
||
code
===
CharCode
.
Dash
||
code
===
CharCode
.
Period
||
code
===
CharCode
.
Underline
||
code
===
CharCode
.
Tilde
||
(
allowSlash
&&
code
===
CharCode
.
Slash
)
)
{
// check if we are delaying native encode
if
(
nativeEncodePos
!==
-
1
)
{
res
+=
encodeURIComponent
(
uriComponent
.
substring
(
nativeEncodePos
,
pos
));
nativeEncodePos
=
-
1
;
}
// check if we write into a new string (by default we try to return the param)
if
(
res
!==
undefined
)
{
res
+=
uriComponent
.
charAt
(
pos
);
}
}
else
{
// encoding needed, we need to allocate a new string
if
(
res
===
undefined
)
{
res
=
uriComponent
.
substr
(
0
,
pos
);
}
// check with default table first
let
escaped
=
encodeTable
[
code
];
if
(
escaped
!==
undefined
)
{
// check if we are delaying native encode
if
(
nativeEncodePos
!==
-
1
)
{
res
+=
encodeURIComponent
(
uriComponent
.
substring
(
nativeEncodePos
,
pos
));
nativeEncodePos
=
-
1
;
}
// append escaped variant to result
res
+=
escaped
;
}
else
if
(
nativeEncodePos
===
-
1
)
{
// use native encode only when needed
nativeEncodePos
=
pos
;
}
}
}
if
(
nativeEncodePos
!==
-
1
)
{
res
+=
encodeURIComponent
(
uriComponent
.
substring
(
nativeEncodePos
));
}
return
res
!==
undefined
?
res
:
uriComponent
;
}
function
encodeURIComponentMinimal
(
path
:
string
):
string
{
let
res
:
string
=
undefined
;
for
(
let
pos
=
0
;
pos
<
path
.
length
;
pos
++
)
{
let
code
=
path
.
charCodeAt
(
pos
);
if
(
code
===
CharCode
.
Hash
||
code
===
CharCode
.
QuestionMark
)
{
if
(
res
===
undefined
)
{
res
=
path
.
substr
(
0
,
pos
);
}
res
+=
encodeTable
[
code
];
}
else
{
if
(
res
!==
undefined
)
{
res
+=
path
[
pos
];
}
}
}
return
res
!==
undefined
?
res
:
path
;
}
/**
* Compute `fsPath` for the given uri
...
...
@@ -408,11 +496,10 @@ function _makeFsPath(uri: URI): string {
function
_asFormatted
(
uri
:
URI
,
skipEncoding
:
boolean
):
string
{
const
encoder
=
!
skipEncoding
?
encodeURIComponent
2
:
encode
Noop
;
?
encodeURIComponent
Fast
:
encode
URIComponentMinimal
;
let
res
=
''
;
let
{
scheme
,
authority
,
path
,
query
,
fragment
}
=
uri
;
if
(
scheme
)
{
res
+=
scheme
;
...
...
@@ -430,59 +517,48 @@ function _asFormatted(uri: URI, skipEncoding: boolean): string {
authority
=
authority
.
substr
(
idx
+
1
);
idx
=
userinfo
.
indexOf
(
'
:
'
);
if
(
idx
===
-
1
)
{
res
+=
encoder
(
userinfo
);
res
+=
encoder
(
userinfo
,
false
);
}
else
{
// <user>:<pass>@<auth>
res
+=
encoder
(
userinfo
.
substr
(
0
,
idx
));
res
+=
encoder
(
userinfo
.
substr
(
0
,
idx
)
,
false
);
res
+=
'
:
'
;
res
+=
encoder
(
userinfo
.
substr
(
idx
+
1
));
res
+=
encoder
(
userinfo
.
substr
(
idx
+
1
)
,
false
);
}
res
+=
'
@
'
;
}
authority
=
authority
.
toLowerCase
();
idx
=
authority
.
indexOf
(
'
:
'
);
if
(
idx
===
-
1
)
{
res
+=
encoder
(
authority
);
res
+=
encoder
(
authority
,
false
);
}
else
{
// <auth>:<port>
res
+=
encoder
(
authority
.
substr
(
0
,
idx
));
res
+=
encoder
(
authority
.
substr
(
0
,
idx
)
,
false
);
res
+=
authority
.
substr
(
idx
);
}
}
if
(
path
)
{
// lower-case windows drive letters in /C:/fff or C:/fff
const
m
=
_upperCaseDrive
.
exec
(
path
);
if
(
m
)
{
if
(
m
[
1
])
{
path
=
'
/
'
+
m
[
2
].
toLowerCase
()
+
path
.
substr
(
3
);
// "/c:".length === 3
}
else
{
path
=
m
[
2
].
toLowerCase
()
+
path
.
substr
(
2
);
// // "c:".length === 2
if
(
path
.
length
>=
3
&&
path
.
charCodeAt
(
0
)
===
CharCode
.
Slash
&&
path
.
charCodeAt
(
2
)
===
CharCode
.
Colon
)
{
let
code
=
path
.
charCodeAt
(
1
);
if
(
code
>=
CharCode
.
A
&&
code
<=
CharCode
.
Z
)
{
path
=
`/
${
String
.
fromCharCode
(
code
+
32
)}
:
${
path
.
substr
(
3
)}
`
;
// "/c:".length === 3
}
}
// encode every segement but not slashes
// make sure that # and ? are always encoded
// when occurring in paths - otherwise the result
// cannot be parsed back again
let
lastIdx
=
0
;
while
(
true
)
{
let
idx
=
path
.
indexOf
(
_slash
,
lastIdx
);
if
(
idx
===
-
1
)
{
res
+=
encoder
(
path
.
substring
(
lastIdx
));
break
;
}
else
if
(
path
.
length
>=
2
&&
path
.
charCodeAt
(
1
)
===
CharCode
.
Colon
)
{
let
code
=
path
.
charCodeAt
(
0
);
if
(
code
>=
CharCode
.
A
&&
code
<=
CharCode
.
Z
)
{
path
=
`
${
String
.
fromCharCode
(
code
+
32
)}
:
${
path
.
substr
(
2
)}
`
;
// "/c:".length === 3
}
res
+=
encoder
(
path
.
substring
(
lastIdx
,
idx
));
res
+=
_slash
;
lastIdx
=
idx
+
1
;
}
// encode the rest of the path
res
+=
encoder
(
path
,
true
);
}
if
(
query
)
{
res
+=
'
?
'
;
res
+=
encoder
(
query
);
res
+=
encoder
(
query
,
false
);
}
if
(
fragment
)
{
res
+=
'
#
'
;
res
+=
encoder
(
fragment
);
res
+=
encoder
(
fragment
,
false
);
}
return
res
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录