Skip to content

Commit bbf878e

Browse files
authored
Add env value sanitization (#1590)
1 parent 1f995f2 commit bbf878e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

scripts/revokeInstallations.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,27 @@ async function main() {
7979
process.exit(1);
8080
}
8181

82+
// Sanitize environment variable value by removing surrounding quotes
83+
const sanitizeEnvValue = (value: string): string => {
84+
const trimmed = value.trim();
85+
// Remove surrounding quotes (single or double) if present
86+
if (
87+
(trimmed.startsWith('"') && trimmed.endsWith('"')) ||
88+
(trimmed.startsWith("'") && trimmed.endsWith("'"))
89+
) {
90+
return trimmed.slice(1, -1);
91+
}
92+
return trimmed;
93+
};
94+
8295
// Read and parse .env file
8396
const envContent = await readFile(envPath, "utf-8");
8497
const envVars: Record<string, string> = {};
8598

8699
envContent.split("\n").forEach((line) => {
87100
const [key, value] = line.split("=");
88101
if (key && value && !key.startsWith("#")) {
89-
envVars[key.trim()] = value.trim();
102+
envVars[key.trim()] = sanitizeEnvValue(value);
90103
}
91104
});
92105

0 commit comments

Comments
 (0)