uri - throw when having an uri without scheme (still warn in the extension host)
This commit is contained in:
parent
50f95b61d3
commit
f8a736c017
4 changed files with 26 additions and 5 deletions
|
@ -11,12 +11,26 @@ const _schemePattern = /^\w[\w\d+.-]*$/;
|
|||
const _singleSlashStart = /^\//;
|
||||
const _doubleSlashStart = /^\/\//;
|
||||
|
||||
let _throwOnMissingSchema: boolean = true;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function setUriThrowOnMissingScheme(value: boolean): boolean {
|
||||
const old = _throwOnMissingSchema;
|
||||
_throwOnMissingSchema = value;
|
||||
return old;
|
||||
}
|
||||
|
||||
function _validateUri(ret: URI): void {
|
||||
|
||||
// scheme, must be set
|
||||
if (!ret.scheme) {
|
||||
// throw new Error(`[UriError]: Scheme is missing: {scheme: "", authority: "${ret.authority}", path: "${ret.path}", query: "${ret.query}", fragment: "${ret.fragment}"}`);
|
||||
console.warn(`[UriError]: Scheme is missing: {scheme: "", authority: "${ret.authority}", path: "${ret.path}", query: "${ret.query}", fragment: "${ret.fragment}"}`);
|
||||
if (_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}"}`);
|
||||
}
|
||||
}
|
||||
|
||||
// scheme, https://tools.ietf.org/html/rfc3986#section-3.1
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import * as assert from 'assert';
|
||||
import { dirname, basename, distinctParents, joinPath, isEqual, isEqualOrParent, hasToIgnoreCase, normalizePath, isAbsolutePath, isMalformedFileUri } from 'vs/base/common/resources';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { URI, setUriThrowOnMissingScheme } from 'vs/base/common/uri';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
|
||||
suite('Resources', () => {
|
||||
|
@ -208,8 +208,10 @@ suite('Resources', () => {
|
|||
});
|
||||
|
||||
function assertMalformedFileUri(path: string, expected: string) {
|
||||
const old = setUriThrowOnMissingScheme(false);
|
||||
const newURI = isMalformedFileUri(URI.parse(path));
|
||||
assert.equal(newURI && newURI.toString(), expected);
|
||||
setUriThrowOnMissingScheme(old);
|
||||
}
|
||||
|
||||
test('isMalformedFileUri', () => {
|
||||
|
@ -227,4 +229,4 @@ suite('Resources', () => {
|
|||
assertMalformedFileUri('foo://dadie/foo/bar', void 0);
|
||||
assertMalformedFileUri('foo:///dadie/foo/bar', void 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
1
src/vs/monaco.d.ts
vendored
1
src/vs/monaco.d.ts
vendored
|
@ -76,6 +76,7 @@ declare namespace monaco {
|
|||
*/
|
||||
readonly onCancellationRequested: IEvent<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uniform Resource Identifier (Uri) http://tools.ietf.org/html/rfc3986.
|
||||
* This class is a simple parser which creates the basic component parts
|
||||
|
|
|
@ -19,12 +19,16 @@ import { ExtensionActivatedByEvent } from 'vs/workbench/api/node/extHostExtensio
|
|||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IMessagePassingProtocol } from 'vs/base/parts/ipc/node/ipc';
|
||||
import { RPCProtocol } from 'vs/workbench/services/extensions/node/rpcProtocol';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { URI, setUriThrowOnMissingScheme } from 'vs/base/common/uri';
|
||||
import { ExtHostLogService } from 'vs/workbench/api/node/extHostLogService';
|
||||
import { timeout } from 'vs/base/common/async';
|
||||
import { Counter } from 'vs/base/common/numbers';
|
||||
import { CancellationTokenSource } from 'vs/base/common/cancellation';
|
||||
|
||||
// we don't (yet) throw when extensions parse
|
||||
// uris that have no scheme
|
||||
setUriThrowOnMissingScheme(false);
|
||||
|
||||
const nativeExit = process.exit.bind(process);
|
||||
function patchProcess(allowExit: boolean) {
|
||||
process.exit = function (code?: number) {
|
||||
|
|
Loading…
Reference in a new issue