提交 9d631901 编写于 作者: J Johannes Rieken

When checking snippet files, don't use indexOf but isEqualOrParent, #56403

上级 7cdc647a
......@@ -25,15 +25,20 @@ export function basenameOrAuthority(resource: URI): string {
return basename(resource) || resource.authority;
}
export function isEqualOrParent(resource: URI, candidate: URI, ignoreCase?: boolean): boolean {
if (resource.scheme === candidate.scheme) {
if (resource.scheme === Schemas.file) {
return paths.isEqualOrParent(resource.fsPath, candidate.fsPath, ignoreCase);
/**
*
* @param base A uri which is "longer"
* @param parentCandidate A uri which is "shorter" then `base`
*/
export function isEqualOrParent(base: URI, parentCandidate: URI, ignoreCase?: boolean): boolean {
if (base.scheme === parentCandidate.scheme) {
if (base.scheme === Schemas.file) {
return paths.isEqualOrParent(base.fsPath, parentCandidate.fsPath, ignoreCase);
}
if (!isEqualAuthority(resource.authority, candidate.authority, ignoreCase)) {
if (!isEqualAuthority(base.authority, parentCandidate.authority, ignoreCase)) {
return false;
}
return paths.isEqualOrParent(resource.path, candidate.path, ignoreCase, '/');
return paths.isEqualOrParent(base.path, parentCandidate.path, ignoreCase, '/');
}
return false;
......
......@@ -76,7 +76,7 @@ namespace schema {
const extensionLocation = extension.description.extensionLocation;
const snippetLocation = resources.joinPath(extensionLocation, snippet.path);
if (snippetLocation.path.indexOf(extensionLocation.path) !== 0) {
if (!resources.isEqualOrParent(snippetLocation, extensionLocation)) {
extension.collector.error(localize(
'invalid.path.1',
"Expected `contributes.{0}.path` ({1}) to be included inside extension's folder ({2}). This might make the extension non-portable.",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册