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

uri - throw when having an uri without scheme (still warn in the extension host)

上级 50f95b61
......@@ -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);
});
});
\ No newline at end of file
});
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册