Skip to content

Commit a490efe

Browse files
jqnatividadclaude
andcommitted
fix(mcp): hoist psEscape to module scope and remove redundant escaping of fixed binaryName
Moves psEscape helper from inside the try block to module scope (avoids unnecessary allocation on non-Windows platforms) and drops the redundant psEscape(binaryName) call since binaryName is always "qsvmcp"/"qsvmcp.exe". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3adddef commit a490efe

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

.claude/skills/src/installer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const GITHUB_LATEST_RELEASE_URL = "https://api.github.com/repos/dathere/qsv/rele
4747
/** Timeout for GitHub API and download requests (60 seconds) */
4848
const FETCH_TIMEOUT_MS = 60_000;
4949

50+
/** Escape single quotes for PowerShell single-quoted strings */
51+
const psEscape = (s: string) => s.replace(/'/g, "''");
52+
5053
/**
5154
* Get the asset filename suffix for the current platform, or null if unsupported.
5255
*/
@@ -114,9 +117,6 @@ async function downloadAndInstall(url: string): Promise<InstallResult> {
114117
const tempDir = mkdtempSync(join(tmpdir(), "qsv-install-"));
115118

116119
try {
117-
// Helper to escape single quotes for PowerShell single-quoted strings
118-
const psEscape = (s: string) => s.replace(/'/g, "''");
119-
120120
// 1. Download the zip file
121121
const response = await fetch(url, {
122122
headers: { "User-Agent": "qsv-mcp-server" },
@@ -156,7 +156,7 @@ async function downloadAndInstall(url: string): Promise<InstallResult> {
156156
const findResult = execFileSync("powershell", [
157157
"-NoProfile",
158158
"-Command",
159-
`(Get-ChildItem -Path '${psEscape(tempDir)}' -Recurse -Filter '${psEscape(binaryName)}' | Select-Object -First 1).FullName`,
159+
`(Get-ChildItem -Path '${psEscape(tempDir)}' -Recurse -Filter '${binaryName}' | Select-Object -First 1).FullName`,
160160
], { encoding: "utf8", timeout: 10_000 }).trim();
161161
if (findResult) {
162162
extractedPath = findResult;

0 commit comments

Comments
 (0)