Skip to content

Commit 8fa91ca

Browse files
author
Loïc Mangeonjean
committed
fix: improve XMLHttpRequest patch
make it return a 404 for unknown extension file
1 parent 623f505 commit 8fa91ca

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

scripts/vscode.patch

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ index b83a462131d..5555f431ba0 100644
543543
performance.mark('code/extHost/didInitAPI');
544544

545545
diff --git a/src/vs/workbench/api/worker/extensionHostWorker.ts b/src/vs/workbench/api/worker/extensionHostWorker.ts
546-
index 6e6f8845da5..74ecefe68f1 100644
546+
index 6e6f8845da5..89cab1e16da 100644
547547
--- a/src/vs/workbench/api/worker/extensionHostWorker.ts
548548
+++ b/src/vs/workbench/api/worker/extensionHostWorker.ts
549549
@@ -15,7 +15,6 @@ import * as performance from 'vs/base/common/performance';
@@ -554,7 +554,16 @@ index 6e6f8845da5..74ecefe68f1 100644
554554
import { URI } from 'vs/base/common/uri';
555555

556556
//#region --- Define, capture, and override some globals
557-
@@ -89,66 +88,155 @@ self.addEventListener = () => console.trace(`'addEventListener' has been blocked
557+
@@ -47,7 +46,7 @@ function shouldTransformUri(uri: string): boolean {
558+
// In principle, we could convert any URI, but we have concerns
559+
// that parsing https URIs might end up decoding escape characters
560+
// and result in an unintended transformation
561+
- return /^(file|vscode-remote):/i.test(uri);
562+
+ return /^(file|extension|vscode-remote):/i.test(uri);
563+
}
564+
565+
const nativeFetch = fetch.bind(self);
566+
@@ -89,66 +88,167 @@ self.addEventListener = () => console.trace(`'addEventListener' has been blocked
558567
(<any>self)['webkitResolveLocalFileSystemSyncURL'] = undefined;
559568
(<any>self)['webkitResolveLocalFileSystemURL'] = undefined;
560569

@@ -620,8 +629,20 @@ index 6e6f8845da5..74ecefe68f1 100644
620629
+ return nativeFetch(asWorkerBrowserUrl(input), init);
621630
+ };
622631
+ self.XMLHttpRequest = class extends XMLHttpRequest {
632+
+ private notFound = false;
623633
+ override open(method: string, url: string | URL, async?: boolean, username?: string | null, password?: string | null): void {
624-
+ return super.open(method, asWorkerBrowserUrl(url), async ?? true, username, password);
634+
+ const transformedUrl = asWorkerBrowserUrl(url);
635+
+ this.notFound = transformedUrl.startsWith('extension:');
636+
+ return super.open(method, transformedUrl, async ?? true, username, password);
637+
+ }
638+
+ override send(body?: Document | XMLHttpRequestBodyInit | null | undefined): void {
639+
+ if (this.notFound) {
640+
+ return;
641+
+ }
642+
+ super.send(body);
643+
+ }
644+
+ override get status() {
645+
+ return this.notFound ? 404 : super.status;
625646
+ }
626647
+ };
627648
+ const nativeImportScripts = importScripts.bind(self);
@@ -764,7 +785,7 @@ index 6e6f8845da5..74ecefe68f1 100644
764785
}
765786

766787
//#endregion ---
767-
@@ -255,6 +343,7 @@ export function create(): { onmessage: (message: any) => void } {
788+
@@ -255,6 +355,7 @@ export function create(): { onmessage: (message: any) => void } {
768789
);
769790

770791
patchFetching(uri => extHostMain.asBrowserUri(uri));

0 commit comments

Comments
 (0)