提交 c1555978 编写于 作者: J Johannes Rieken

add Uri.parse(value, strict) so that missing scheme throw

上级 1c60855e
......@@ -449,7 +449,7 @@ export class ResourceMap<T> {
}
public keys(): URI[] {
return keys(this.map).map(URI.parse);
return keys(this.map).map(k => URI.parse(k));
}
public clone(): ResourceMap<T> {
......
......@@ -21,11 +21,11 @@ export function setUriThrowOnMissingScheme(value: boolean): boolean {
return old;
}
function _validateUri(ret: URI): void {
function _validateUri(ret: URI, _strict?: boolean): void {
// scheme, must be set
if (!ret.scheme) {
if (_throwOnMissingSchema) {
if (_strict || _throwOnMissingSchema) {
throw new Error(`[UriError]: Scheme is missing: {scheme: "", authority: "${ret.authority}", path: "${ret.path}", query: "${ret.query}", fragment: "${ret.fragment}"}`);
} else {
console.warn(`[UriError]: Scheme is missing: {scheme: "", authority: "${ret.authority}", path: "${ret.path}", query: "${ret.query}", fragment: "${ret.fragment}"}`);
......@@ -141,7 +141,7 @@ export class URI implements UriComponents {
/**
* @internal
*/
protected constructor(scheme: string, authority?: string, path?: string, query?: string, fragment?: string);
protected constructor(scheme: string, authority?: string, path?: string, query?: string, fragment?: string, _strict?: boolean);
/**
* @internal
......@@ -151,7 +151,7 @@ export class URI implements UriComponents {
/**
* @internal
*/
protected constructor(schemeOrData: string | UriComponents, authority?: string, path?: string, query?: string, fragment?: string) {
protected constructor(schemeOrData: string | UriComponents, authority?: string, path?: string, query?: string, fragment?: string, _strict?: boolean) {
if (typeof schemeOrData === 'object') {
this.scheme = schemeOrData.scheme || _empty;
......@@ -169,7 +169,7 @@ export class URI implements UriComponents {
this.query = query || _empty;
this.fragment = fragment || _empty;
_validateUri(this);
_validateUri(this, _strict);
}
}
......@@ -261,7 +261,7 @@ export class URI implements UriComponents {
*
* @param value A string which represents an URI (see `URI#toString`).
*/
public static parse(value: string): URI {
public static parse(value: string, _strict: boolean = false): URI {
const match = _regexp.exec(value);
if (!match) {
return new _URI(_empty, _empty, _empty, _empty, _empty);
......@@ -272,6 +272,7 @@ export class URI implements UriComponents {
decodeURIComponent(match[5] || _empty),
decodeURIComponent(match[7] || _empty),
decodeURIComponent(match[9] || _empty),
_strict
);
}
......
......@@ -151,7 +151,7 @@ declare namespace monaco {
*
* @param value A string which represents an Uri (see `Uri#toString`).
*/
static parse(value: string): Uri;
static parse(value: string, _strict?: boolean): Uri;
/**
* Creates a new Uri from a file system path, e.g. `c:\my\files`,
* `/usr/home`, or `\\server\share\some\path`.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册