From c6b45040b16776b2de5636a4fd62c3494ceb7064 Mon Sep 17 00:00:00 2001 From: dankeboy36 Date: Thu, 19 Feb 2026 15:36:59 +0100 Subject: [PATCH] fix: use vscode.Uri when building readonly fs path Closes #64 Signed-off-by: dankeboy36 --- src/capturer/fsProviders.ts | 7 +++++-- src/test/suite/fsProviders.test.ts | 20 ++++++++++++++++++++ webpack.config.js | 3 +-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/capturer/fsProviders.ts b/src/capturer/fsProviders.ts index 242ed64..465c9d5 100644 --- a/src/capturer/fsProviders.ts +++ b/src/capturer/fsProviders.ts @@ -57,14 +57,17 @@ export class CrashReportContentProvider export function toReadonlyLibraryUri(filePath: string): vscode.Uri { return vscode.Uri.from({ scheme: readonlyLibraryScheme, - path: filePath.replace(/\\/g, '/'), + path: vscode.Uri.file(filePath).path, query: `source=${encodeURIComponent(filePath)}`, }) } export function toSourcePathFromReadonlyUri(uri: vscode.Uri): string { const source = new URLSearchParams(uri.query).get('source') - return source && source.length > 0 ? source : uri.path + if (source && source.length > 0) { + return source + } + return /^\/[A-Za-z]:\//.test(uri.path) ? uri.path.slice(1) : uri.path } export class ReadonlyFsProvider diff --git a/src/test/suite/fsProviders.test.ts b/src/test/suite/fsProviders.test.ts index 84c8339..68a310b 100644 --- a/src/test/suite/fsProviders.test.ts +++ b/src/test/suite/fsProviders.test.ts @@ -54,6 +54,26 @@ describe('fsProviders', () => { assert.equal(toSourcePathFromReadonlyUri(fallback), '/tmp/no-query.cpp') }) + it('creates absolute readonly uris for Windows drive-letter paths', () => { + const sourcePath = + 'C:\\Users\\xxx\\AppData\\Local\\Arduino15\\packages\\esp32\\hardware\\esp32\\3.2.1\\cores\\esp32\\main.cpp' + const uri = toReadonlyLibraryUri(sourcePath) + const serialized = uri.toString() + + assert.equal(uri.scheme, readonlyLibraryScheme) + assert.equal(toSourcePathFromReadonlyUri(uri), sourcePath) + assert.equal(serialized.startsWith(`${readonlyLibraryScheme}:/`), true) + + const fallback = vscode.Uri.from({ + scheme: readonlyLibraryScheme, + path: '/C:/Users/xxx/AppData/Local/Arduino15/main.cpp', + }) + assert.equal( + toSourcePathFromReadonlyUri(fallback), + 'C:/Users/xxx/AppData/Local/Arduino15/main.cpp' + ) + }) + it('reads readonly files and blocks write operations', async () => { const root = await fs.mkdtemp(path.join(os.tmpdir(), 'capturer-fs-')) const subDir = path.join(root, 'sub') diff --git a/webpack.config.js b/webpack.config.js index 417ae8b..b2e2eb1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,7 +1,6 @@ -//@ts-check +// @ts-check 'use strict' -// eslint-disable-next-line @typescript-eslint/no-var-requires const path = require('path') /** @type {import('webpack').Configuration} */