Skip to content

Commit c155597

Browse files
committed
add Uri.parse(value, strict) so that missing scheme throw
1 parent 1c60855 commit c155597

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/vs/base/common/map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ export class ResourceMap<T> {
449449
}
450450

451451
public keys(): URI[] {
452-
return keys(this.map).map(URI.parse);
452+
return keys(this.map).map(k => URI.parse(k));
453453
}
454454

455455
public clone(): ResourceMap<T> {

src/vs/base/common/uri.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ export function setUriThrowOnMissingScheme(value: boolean): boolean {
2121
return old;
2222
}
2323

24-
function _validateUri(ret: URI): void {
24+
function _validateUri(ret: URI, _strict?: boolean): void {
2525

2626
// scheme, must be set
2727
if (!ret.scheme) {
28-
if (_throwOnMissingSchema) {
28+
if (_strict || _throwOnMissingSchema) {
2929
throw new Error(`[UriError]: Scheme is missing: {scheme: "", authority: "${ret.authority}", path: "${ret.path}", query: "${ret.query}", fragment: "${ret.fragment}"}`);
3030
} else {
3131
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 {
141141
/**
142142
* @internal
143143
*/
144-
protected constructor(scheme: string, authority?: string, path?: string, query?: string, fragment?: string);
144+
protected constructor(scheme: string, authority?: string, path?: string, query?: string, fragment?: string, _strict?: boolean);
145145

146146
/**
147147
* @internal
@@ -151,7 +151,7 @@ export class URI implements UriComponents {
151151
/**
152152
* @internal
153153
*/
154-
protected constructor(schemeOrData: string | UriComponents, authority?: string, path?: string, query?: string, fragment?: string) {
154+
protected constructor(schemeOrData: string | UriComponents, authority?: string, path?: string, query?: string, fragment?: string, _strict?: boolean) {
155155

156156
if (typeof schemeOrData === 'object') {
157157
this.scheme = schemeOrData.scheme || _empty;
@@ -169,7 +169,7 @@ export class URI implements UriComponents {
169169
this.query = query || _empty;
170170
this.fragment = fragment || _empty;
171171

172-
_validateUri(this);
172+
_validateUri(this, _strict);
173173
}
174174
}
175175

@@ -261,7 +261,7 @@ export class URI implements UriComponents {
261261
*
262262
* @param value A string which represents an URI (see `URI#toString`).
263263
*/
264-
public static parse(value: string): URI {
264+
public static parse(value: string, _strict: boolean = false): URI {
265265
const match = _regexp.exec(value);
266266
if (!match) {
267267
return new _URI(_empty, _empty, _empty, _empty, _empty);
@@ -272,6 +272,7 @@ export class URI implements UriComponents {
272272
decodeURIComponent(match[5] || _empty),
273273
decodeURIComponent(match[7] || _empty),
274274
decodeURIComponent(match[9] || _empty),
275+
_strict
275276
);
276277
}
277278

src/vs/monaco.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ declare namespace monaco {
151151
*
152152
* @param value A string which represents an Uri (see `Uri#toString`).
153153
*/
154-
static parse(value: string): Uri;
154+
static parse(value: string, _strict?: boolean): Uri;
155155
/**
156156
* Creates a new Uri from a file system path, e.g. `c:\my\files`,
157157
* `/usr/home`, or `\\server\share\some\path`.

0 commit comments

Comments
 (0)