Skip to content

Commit 2ac44b1

Browse files
authored
Ensure decoded archive fs paths are never empty (#648)
Empty paths should be replaced as '/'. This is a fix for a bug introduced in 899f988.
1 parent ef5d7bf commit 2ac44b1

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

extensions/ql-vscode/src/archive-filesystem-provider.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export function decodeSourceArchiveUri(uri: vscode.Uri): ZipFileReference {
117117
// Uri is malformed, but this is recoverable
118118
logger.log(`Warning: ${new InvalidSourceArchiveUriError(uri).message}`);
119119
return {
120-
pathWithinSourceArchive: '',
120+
pathWithinSourceArchive: '/',
121121
sourceArchiveZipPath: uri.path
122122
};
123123
}
@@ -129,7 +129,7 @@ export function decodeSourceArchiveUri(uri: vscode.Uri): ZipFileReference {
129129
if (isNaN(zipPathStartIndex) || isNaN(zipPathEndIndex))
130130
throw new InvalidSourceArchiveUriError(uri);
131131
return {
132-
pathWithinSourceArchive: uri.path.substring(zipPathEndIndex),
132+
pathWithinSourceArchive: uri.path.substring(zipPathEndIndex) || '/',
133133
sourceArchiveZipPath: uri.path.substring(zipPathStartIndex, zipPathEndIndex),
134134
};
135135
}

extensions/ql-vscode/src/vscode-tests/no-workspace/archive-filesystem-provider.test.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe('source archive uri encoding', function() {
142142
name: 'Empty path',
143143
input: {
144144
sourceArchiveZipPath: '/home/folder/src.zip',
145-
pathWithinSourceArchive: ''
145+
pathWithinSourceArchive: '/'
146146
}
147147
}
148148
];
@@ -153,11 +153,22 @@ describe('source archive uri encoding', function() {
153153
});
154154
}
155155

156+
it('should decode an empty path as a "/"', () => {
157+
const uri = encodeSourceArchiveUri({
158+
pathWithinSourceArchive: '',
159+
sourceArchiveZipPath: 'a/b/c'
160+
});
161+
expect(decodeSourceArchiveUri(uri)).to.deep.eq({
162+
pathWithinSourceArchive: '/',
163+
sourceArchiveZipPath: 'a/b/c'
164+
});
165+
});
166+
156167
it('should encode a uri at the root of the archive', () => {
157168
const path = '/a/b/c/src.zip';
158169
const uri = encodeArchiveBasePath(path);
159170
expect(uri.path).to.eq(path);
160-
expect(decodeSourceArchiveUri(uri).pathWithinSourceArchive).to.eq('');
171+
expect(decodeSourceArchiveUri(uri).pathWithinSourceArchive).to.eq('/');
161172
expect(decodeSourceArchiveUri(uri).sourceArchiveZipPath).to.eq(path);
162173
expect(uri.authority).to.eq('0-14');
163174
});
@@ -168,7 +179,7 @@ describe('source archive uri encoding', function() {
168179
expect(uri.authority).to.eq('');
169180
expect(decodeSourceArchiveUri(uri)).to.deep.eq({
170181
sourceArchiveZipPath: '/a/b/c/src.zip',
171-
pathWithinSourceArchive: ''
182+
pathWithinSourceArchive: '/'
172183
});
173184
});
174185
});

0 commit comments

Comments
 (0)