Skip to content

Commit

Permalink
Trailing colons in env breaks things
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Jan 16, 2024
1 parent ed796ae commit d9eb602
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/prefab/construct-env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Deno.test("construct_env.ts", async runner => {
try {
const rv = await specimen({ installations })
assertEquals(rv['FOO_FLAGS'], "bar bar bar bar ${FOO_FLAGS} baz${FOO_FLAGS} baz${FOO_FLAGS} baz${FOO_FLAGS} baz") //FIXME lol
assertEquals(rv['PATH'], `/opt/bin:${tmp.join('foo/v2.3.4/bin')}:\${PATH}`)
assertEquals(rv['PATH'], `/opt/bin:${tmp.join('foo/v2.3.4/bin')}\${PATH:+:$PATH}`)
} finally {
stub2.restore()
tmp.rm({recursive: true})
Expand Down
4 changes: 4 additions & 0 deletions src/prefab/construct-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export default async function(pkgenv: { installations: Installation[] }) {

for (const key in rv) {
rv[key] = rv[key].replaceAll(new RegExp(`\\$${key}\\b`, 'g'), `\${${key}}`)
// don’t end with a trailing `:` since that is sometimes interpreted as CWD and can break things
// instead of `foo:${PATH}` we end up with `foo${PATH:+:PATH}` which is not POSIX but works
// with all realy shells to avoid the trailing `:`
rv[key] = rv[key].replaceAll(new RegExp(`:\\$\{${key}}`, 'g'), `\${${key}:+:$${key}}`)
}

return rv
Expand Down

0 comments on commit d9eb602

Please sign in to comment.