mirror of https://github.com/aminya/setup-cpp
fix: escape the spaces when adding environment variables and paths
This commit is contained in:
parent
a78b699485
commit
41d161c37f
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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()) {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue