Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit 7766118

Browse files
committed
use URL instead of vscode.Uri to avoid unnecessary percent encoding
The `toString` function on `vscode.Uri` will aggressively apply percent encoding even if unnecessary for some character+component cases. This affects the `+` in the filename of nightly versions and the `=` in the query parameter. While it is valid to percent encode even if unnecessary, this can still lead to confusion about whether the url is valid if the reader is unfamiliar with the rules around percent encoding. There is no downside to just using `URL` instead of `vscode.Uri` so that we get more readable urls. This can be especially helpful if the encoded url happens to be shown to the extension user through the error message of an exception as an example.
1 parent 51ead57 commit 7766118

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/versionManager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,22 @@ async function installFromMirror(
157157
abortController.abort();
158158
});
159159

160-
const artifactUrl = vscode.Uri.joinPath(mirrorUrl, fileName);
160+
const artifactUrl = new URL(fileName, mirrorUrl.toString());
161161
/** https://github.com/mlugg/setup-zig adds a `?source=github-actions` query parameter so we add our own. */
162-
const artifactUrlWithQuery = artifactUrl.with({ query: "source=vscode-zig" });
162+
artifactUrl.searchParams.set("source", "vscode-zig");
163163

164-
const artifactMinisignUrl = vscode.Uri.joinPath(mirrorUrl, `${fileName}.minisig`);
165-
const artifactMinisignUrlWithQuery = artifactMinisignUrl.with({ query: "source=vscode-zig" });
164+
const artifactMinisignUrl = new URL(`${fileName}.minisig`, mirrorUrl.toString());
165+
artifactMinisignUrl.searchParams.set("source", "vscode-zig");
166166

167-
const signatureResponse = await fetch(artifactMinisignUrlWithQuery.toString(), {
167+
const signatureResponse = await fetch(artifactMinisignUrl, {
168168
signal: abortController.signal,
169169
});
170170

171171
if (signatureResponse.status !== 200) {
172172
throw new Error(`${signatureResponse.statusText} (${signatureResponse.status.toString()})`);
173173
}
174174

175-
let artifactResponse = await fetch(artifactUrlWithQuery.toString(), {
175+
let artifactResponse = await fetch(artifactUrl, {
176176
signal: abortController.signal,
177177
});
178178

0 commit comments

Comments
 (0)