Skip to content

Commit 85823bc

Browse files
committed
Avoid infinite recursion when expanding windows environment variables
1 parent 7825358 commit 85823bc

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/proc.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,16 @@ export function patchOSEnviron({ caller, extraPath, extraVars }) {
6666

6767
// Expand Windows environment variables in %xxx% format
6868
const reWindowsEnvVar = /\%([^\%]+)\%/g;
69-
while (IS_WINDOWS && reWindowsEnvVar.test(process.env.PLATFORMIO_PATH)) {
69+
const expandedEnvVars = [];
70+
while (IS_WINDOWS) {
71+
const matchedEnvVar = reWindowsEnvVar.exec(process.env.PLATFORMIO_PATH);
72+
if (!matchedEnvVar || expandedEnvVars.includes(matchedEnvVar[1])) {
73+
break;
74+
}
75+
expandedEnvVars.push(matchedEnvVar[1]);
7076
process.env.PLATFORMIO_PATH = process.env.PLATFORMIO_PATH.replace(
71-
reWindowsEnvVar,
72-
(_, envvar) => {
73-
return process.env[envvar] || '';
74-
}
77+
matchedEnvVar[0],
78+
process.env[matchedEnvVar[1]] || ''
7579
);
7680
}
7781

0 commit comments

Comments
 (0)