Ensure decoded archive fs paths are never empty (#648)
Empty paths should be replaced as '/'. This is a fix for a bug
introduced in 899f988df8.
This commit is contained in:
@@ -117,7 +117,7 @@ export function decodeSourceArchiveUri(uri: vscode.Uri): ZipFileReference {
|
|||||||
// Uri is malformed, but this is recoverable
|
// Uri is malformed, but this is recoverable
|
||||||
logger.log(`Warning: ${new InvalidSourceArchiveUriError(uri).message}`);
|
logger.log(`Warning: ${new InvalidSourceArchiveUriError(uri).message}`);
|
||||||
return {
|
return {
|
||||||
pathWithinSourceArchive: '',
|
pathWithinSourceArchive: '/',
|
||||||
sourceArchiveZipPath: uri.path
|
sourceArchiveZipPath: uri.path
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ export function decodeSourceArchiveUri(uri: vscode.Uri): ZipFileReference {
|
|||||||
if (isNaN(zipPathStartIndex) || isNaN(zipPathEndIndex))
|
if (isNaN(zipPathStartIndex) || isNaN(zipPathEndIndex))
|
||||||
throw new InvalidSourceArchiveUriError(uri);
|
throw new InvalidSourceArchiveUriError(uri);
|
||||||
return {
|
return {
|
||||||
pathWithinSourceArchive: uri.path.substring(zipPathEndIndex),
|
pathWithinSourceArchive: uri.path.substring(zipPathEndIndex) || '/',
|
||||||
sourceArchiveZipPath: uri.path.substring(zipPathStartIndex, zipPathEndIndex),
|
sourceArchiveZipPath: uri.path.substring(zipPathStartIndex, zipPathEndIndex),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ describe('source archive uri encoding', function() {
|
|||||||
name: 'Empty path',
|
name: 'Empty path',
|
||||||
input: {
|
input: {
|
||||||
sourceArchiveZipPath: '/home/folder/src.zip',
|
sourceArchiveZipPath: '/home/folder/src.zip',
|
||||||
pathWithinSourceArchive: ''
|
pathWithinSourceArchive: '/'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@@ -153,11 +153,22 @@ describe('source archive uri encoding', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it('should decode an empty path as a "/"', () => {
|
||||||
|
const uri = encodeSourceArchiveUri({
|
||||||
|
pathWithinSourceArchive: '',
|
||||||
|
sourceArchiveZipPath: 'a/b/c'
|
||||||
|
});
|
||||||
|
expect(decodeSourceArchiveUri(uri)).to.deep.eq({
|
||||||
|
pathWithinSourceArchive: '/',
|
||||||
|
sourceArchiveZipPath: 'a/b/c'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should encode a uri at the root of the archive', () => {
|
it('should encode a uri at the root of the archive', () => {
|
||||||
const path = '/a/b/c/src.zip';
|
const path = '/a/b/c/src.zip';
|
||||||
const uri = encodeArchiveBasePath(path);
|
const uri = encodeArchiveBasePath(path);
|
||||||
expect(uri.path).to.eq(path);
|
expect(uri.path).to.eq(path);
|
||||||
expect(decodeSourceArchiveUri(uri).pathWithinSourceArchive).to.eq('');
|
expect(decodeSourceArchiveUri(uri).pathWithinSourceArchive).to.eq('/');
|
||||||
expect(decodeSourceArchiveUri(uri).sourceArchiveZipPath).to.eq(path);
|
expect(decodeSourceArchiveUri(uri).sourceArchiveZipPath).to.eq(path);
|
||||||
expect(uri.authority).to.eq('0-14');
|
expect(uri.authority).to.eq('0-14');
|
||||||
});
|
});
|
||||||
@@ -168,7 +179,7 @@ describe('source archive uri encoding', function() {
|
|||||||
expect(uri.authority).to.eq('');
|
expect(uri.authority).to.eq('');
|
||||||
expect(decodeSourceArchiveUri(uri)).to.deep.eq({
|
expect(decodeSourceArchiveUri(uri)).to.deep.eq({
|
||||||
sourceArchiveZipPath: '/a/b/c/src.zip',
|
sourceArchiveZipPath: '/a/b/c/src.zip',
|
||||||
pathWithinSourceArchive: ''
|
pathWithinSourceArchive: '/'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user