Skip to content

Commit

Permalink
fix: escape the spaces when adding environment variables and paths
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed May 11, 2022
1 parent a78b699 commit 41d161c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/setup_cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/setup_cpp.js.map

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/utils/env/addEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()) {
Expand Down
11 changes: 11 additions & 0 deletions src/utils/path/escape_space.ts
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit 41d161c

Please sign in to comment.