fix: escape the spaces when adding environment variables and paths

This commit is contained in:
Amin Yahyaabadi 2022-05-11 16:48:11 -07:00
parent a78b699485
commit 41d161c37f
4 changed files with 18 additions and 4 deletions

2
dist/setup_cpp.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5,9 +5,11 @@ import { appendFileSync, existsSync, readFileSync } from "fs"
import { error, warning } from "../io/io"
import { execPowershell } from "../exec/powershell"
import { delimiter } from "path"
import { escapeSpace } from "../path/escape_space"
/** An add path function that works locally or inside GitHub Actions */
export function addEnv(name: string, val: string | undefined) {
export function addEnv(name: string, valGiven: string | undefined, shouldEscapeSpace: boolean = true) {
const val = shouldEscapeSpace ? escapeSpace(valGiven) : valGiven
try {
if (isGitHubCI()) {
exportVariable(name, val)
@ -26,7 +28,8 @@ export function addEnv(name: string, val: string | undefined) {
}
/** An add path function that works locally or inside GitHub Actions */
export function addPath(path: string) {
export function addPath(pathGiven: string, shouldEscapeSpace: boolean = true) {
const path = shouldEscapeSpace ? escapeSpace(pathGiven) : pathGiven
process.env.PATH = `${path}${delimiter}${process.env.PATH}`
try {
if (isGitHubCI()) {

View File

@ -0,0 +1,11 @@
/// Escape the spaces in the given path
export function escapeSpace(path: string | undefined): string {
if (path === undefined) {
return ""
}
if (process.platform === "win32") {
return path.replace(/(\s+)/g, "%20")
} else {
return path.replace(/(\s+)/g, "\\$1")
}
}