提交 a1f35420 编写于 作者: P pi1024e

Update uri.ts

上级 1b0fd26a
......@@ -48,8 +48,10 @@ function _validateUri(ret: URI, _strict?: boolean): void {
if (!_singleSlashStart.test(ret.path)) {
throw new Error('[UriError]: If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character');
}
} else if (_doubleSlashStart.test(ret.path)) {
throw new Error('[UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//")');
} else {
if (_doubleSlashStart.test(ret.path)) {
throw new Error('[UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//")');
}
}
}
}
......@@ -114,17 +116,17 @@ export class URI implements UriComponents {
if (thing instanceof URI) {
return true;
}
if (thing) {
return typeof (<URI>thing).authority === 'string'
&& typeof (<URI>thing).fragment === 'string'
&& typeof (<URI>thing).path === 'string'
&& typeof (<URI>thing).query === 'string'
&& typeof (<URI>thing).scheme === 'string'
&& typeof (<URI>thing).fsPath === 'function'
&& typeof (<URI>thing).with === 'function'
&& typeof (<URI>thing).toString === 'function';
if (!thing) {
return false;
}
return false;
return typeof (<URI>thing).authority === 'string'
&& typeof (<URI>thing).fragment === 'string'
&& typeof (<URI>thing).path === 'string'
&& typeof (<URI>thing).query === 'string'
&& typeof (<URI>thing).scheme === 'string'
&& typeof (<URI>thing).fsPath === 'function'
&& typeof (<URI>thing).with === 'function'
&& typeof (<URI>thing).toString === 'function';
}
/**
......@@ -279,17 +281,17 @@ export class URI implements UriComponents {
*/
static parse(value: string, _strict: boolean = false): URI {
const match = _regexp.exec(value);
if (match) {
return new _URI(
match[2] || _empty,
decodeURIComponent(match[4] || _empty),
decodeURIComponent(match[5] || _empty),
decodeURIComponent(match[7] || _empty),
decodeURIComponent(match[9] || _empty),
_strict
);
if (!match) {
return new _URI(_empty, _empty, _empty, _empty, _empty);
}
return new _URI(_empty, _empty, _empty, _empty, _empty);
return new _URI(
match[2] || _empty,
decodeURIComponent(match[4] || _empty),
decodeURIComponent(match[5] || _empty),
decodeURIComponent(match[7] || _empty),
decodeURIComponent(match[9] || _empty),
_strict
);
}
/**
......@@ -558,8 +560,10 @@ function encodeURIComponentMinimal(path: string): string {
res = path.substr(0, pos);
}
res += encodeTable[code];
} else if (res !== undefined) {
res += path[pos];
} else {
if (res !== undefined) {
res += path[pos];
}
}
}
return res !== undefined ? res : path;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册