Skip to content

Commit 385df2a

Browse files
Copilotalexr00
andcommitted
Fix: Filter out invalid workspace URIs in URI handler to prevent error on second PR open
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 8fdd68f commit 385df2a

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

src/test/common/uri.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,41 @@
66
import { default as assert } from 'assert';
77
import * as vscode from 'vscode';
88
import { fromOpenOrCheckoutPullRequestWebviewUri } from '../../common/uri';
9+
import { isValidWorkspaceUri } from '../../uriHandler';
910

1011
describe('uri', () => {
12+
describe('isValidWorkspaceUri', () => {
13+
it('should return true for valid Unix file URIs', () => {
14+
const uri = vscode.Uri.parse('file:///home/user/repos/vscode');
15+
assert.strictEqual(isValidWorkspaceUri(uri), true);
16+
});
17+
18+
it('should return true for valid Windows file URIs', () => {
19+
const uri = vscode.Uri.parse('file:///c%3A/Users/dmitriv/repos/vscode');
20+
assert.strictEqual(isValidWorkspaceUri(uri), true);
21+
});
22+
23+
it('should return false for numeric-only path URIs (timestamps)', () => {
24+
const uri = vscode.Uri.parse('file:///1761808101585');
25+
assert.strictEqual(isValidWorkspaceUri(uri), false);
26+
});
27+
28+
it('should return false for non-file scheme URIs', () => {
29+
const uri = vscode.Uri.parse('https://github.com/microsoft/vscode');
30+
assert.strictEqual(isValidWorkspaceUri(uri), false);
31+
});
32+
33+
it('should return true for paths that contain numbers mixed with letters', () => {
34+
const uri = vscode.Uri.parse('file:///home/user123/repos');
35+
assert.strictEqual(isValidWorkspaceUri(uri), true);
36+
});
37+
38+
it('should return true for paths that end with numbers', () => {
39+
const uri = vscode.Uri.parse('file:///home/project/version2');
40+
assert.strictEqual(isValidWorkspaceUri(uri), true);
41+
});
42+
});
43+
1144
describe('fromOpenOrCheckoutPullRequestWebviewUri', () => {
1245
it('should parse the new simplified format with uri parameter', () => {
1346
const uri = vscode.Uri.parse('vscode://github.vscode-pull-request-github/checkout-pull-request?uri=https://github.com/microsoft/vscode-css-languageservice/pull/460');

src/uriHandler.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ import { ReviewsManager } from './view/reviewsManager';
1919

2020
export const PENDING_CHECKOUT_PULL_REQUEST_KEY = 'pendingCheckoutPullRequest';
2121

22+
/**
23+
* Validates that a workspace URI has a valid file path.
24+
* Filters out invalid URIs like file:///1761808101585 (which are numeric timestamps).
25+
*/
26+
export function isValidWorkspaceUri(uri: vscode.Uri): boolean {
27+
if (uri.scheme !== 'file') {
28+
return false;
29+
}
30+
// The fsPath should be a proper file system path, not just a number
31+
// On Windows, valid paths have a drive letter (e.g., C:\...)
32+
// On Unix, valid paths start with / followed by directory names
33+
const fsPath = uri.fsPath;
34+
// Check if the path is just a number (invalid)
35+
if (/^[/\\]?\d+$/.test(fsPath)) {
36+
return false;
37+
}
38+
return true;
39+
}
40+
2241
interface PendingCheckoutPayload {
2342
owner: string;
2443
repo: string;
@@ -199,10 +218,12 @@ export class UriHandler implements vscode.UriHandler {
199218
try {
200219
progress.report({ message: vscode.l10n.t('Locating workspace') });
201220
const remoteUri = vscode.Uri.parse(`https://github.com/${params.owner}/${params.repo}`);
202-
const workspaces = await this._git.getRepositoryWorkspace(remoteUri);
221+
const allWorkspaces = await this._git.getRepositoryWorkspace(remoteUri);
203222
if (token.isCancellationRequested) {
204223
return;
205224
}
225+
// Filter out invalid workspace URIs (e.g., URIs with numeric-only paths)
226+
const workspaces = allWorkspaces?.filter(isValidWorkspaceUri);
206227
if (workspaces && workspaces.length) {
207228
Logger.appendLine(`Found workspaces for ${remoteUri.toString()}: ${workspaces.map(w => w.toString()).join(', ')}`, UriHandler.ID);
208229
progress.report({ message: vscode.l10n.t('Opening workspace') });

0 commit comments

Comments
 (0)