Avoid Uri.parse('')

This commit is contained in:
Christof Marti 2018-08-10 15:54:22 +02:00
parent 4c71656f5d
commit 839a40edb3

View file

@ -249,9 +249,10 @@ export class ExtensionLinter {
private readPackageJsonInfo(folder: Uri, tree: JsonNode) {
const engine = tree && findNodeAtLocation(tree, ['engines', 'vscode']);
const repo = tree && findNodeAtLocation(tree, ['repository', 'url']);
const uri = parseUri(repo.value);
const info: PackageJsonInfo = {
isExtension: !!(engine && engine.type === 'string'),
hasHttpsRepository: !!(repo && repo.type === 'string' && repo.value && parseUri(repo.value).scheme.toLowerCase() === 'https')
hasHttpsRepository: !!(repo && repo.type === 'string' && repo.value && uri && uri.scheme.toLowerCase() === 'https')
};
const str = folder.toString();
const oldInfo = this.folderToPackageJsonInfo[str];
@ -288,6 +289,9 @@ export class ExtensionLinter {
private addDiagnostics(diagnostics: Diagnostic[], document: TextDocument, begin: number, end: number, src: string, context: Context, info: PackageJsonInfo) {
const uri = parseUri(src);
if (!uri) {
return;
}
const scheme = uri.scheme.toLowerCase();
if (scheme && scheme !== 'https' && scheme !== 'data') {
@ -347,7 +351,7 @@ function parseUri(src: string) {
try {
return Uri.parse(encodeURI(src));
} catch (err) {
return Uri.parse('');
return null;
}
}
}