Skip to content

builder: go: Allow equal signs in env vars#1232

Merged
laurentsimon merged 1 commit intoslsa-framework:mainfrom
cfergeau:equal
Nov 16, 2022
Merged

builder: go: Allow equal signs in env vars#1232
laurentsimon merged 1 commit intoslsa-framework:mainfrom
cfergeau:equal

Conversation

@cfergeau
Copy link
Copy Markdown
Contributor

If .slsa-goreleaser.yml contains an env var with multiple '=' signs:

env:
  - CGO_ENABLED=1
  - CGO_CFLAGS=-mmacosx-version-min=11.0

the 'build dry project' GH workflow step fails with "invalid environment
variable: CGO_CFLAGS=-mmacosx-version-min=11.0"
This is caused by the way the env vars are parsed in GoReleaserConfig:setEnvs
which only allow for a single '=' sign.

This commit fixes this by splitting the env string at the first equal sign,
first part is the env var name and won't contain '=' signs, second part
is its value and can contain any number of '='.

This also adds unit tests for this situation, and for env vars with no
values (CGO_CFLAGS=).

This fixes #1231

If .slsa-goreleaser.yml contains an env var with multiple '=' signs:
```
env:
  - CGO_ENABLED=1
  - CGO_CFLAGS=-mmacosx-version-min=11.0
```

the 'build dry project' GH workflow step fails with "invalid environment
variable: CGO_CFLAGS=-mmacosx-version-min=11.0"
This is caused by the way the env vars are parsed in GoReleaserConfig:setEnvs
which only allow for a single '=' sign.

This commit fixes this by splitting the env string at the first equal sign,
first part is the env var name and won't contain '=' signs, second part
is its value and can contain any number of '='.

This also adds unit tests for this situation, and for env vars with no
values (`CGO_CFLAGS=`).

This fixes slsa-framework#1231

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Copy link
Copy Markdown
Collaborator

@laurentsimon laurentsimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@laurentsimon laurentsimon merged commit 1936957 into slsa-framework:main Nov 16, 2022
@ianlewis
Copy link
Copy Markdown
Member

Good, you allowed no value. 👍 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Environment variable value cannot contain =

3 participants