Skip to content

Commit

Permalink
run: allow an equals sign (=) in env var values
Browse files Browse the repository at this point in the history
Fixes #673
  • Loading branch information
jonathanperret committed Aug 23, 2021
1 parent ea756b5 commit 34677ef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* bump github.com/briandowns/spinner from 1.12.0 to 1.16.0
* bump github.com/go-git/go-git/v5 from 5.4.1 to 5.4.2
* feat(command): add command `cron-tasks` to list cron tasks of an application [#670](https://github.com/Scalingo/cli/pull/670)
* fix(run) allow an equals sign (=) in environment variable values [#674](https://github.com/Scalingo/cli/pull/674)

### 1.20.2

Expand Down
2 changes: 1 addition & 1 deletion apps/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (ctx *runContext) buildEnv(cmdEnv []string) (map[string]string, error) {
}

for _, cmdVar := range cmdEnv {
v := strings.Split(cmdVar, "=")
v := strings.SplitN(cmdVar, "=", 2)
if len(v) != 2 || len(v[0]) == 0 || len(v[1]) == 0 {
return nil, fmt.Errorf("Invalid environment, format is '--env VARIABLE=value'")
}
Expand Down
21 changes: 21 additions & 0 deletions apps/run_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package apps

import "testing"

func TestParseEnvVar(t *testing.T) {
ctx := &runContext{}
if env, err := ctx.buildEnv([]string{"TEST=abc"}); err != nil {
t.Fatal(err)
} else if env["TEST"] != "abc" {
t.Fatal(env["TEST"], "should be abc")
}
}

func TestParseEnvVarWithEqualSign(t *testing.T) {
ctx := &runContext{}
if env, err := ctx.buildEnv([]string{"TEST=a=b"}); err != nil {
t.Fatal(err)
} else if env["TEST"] != "a=b" {
t.Fatal(env["TEST"], "should be a=b")
}
}

0 comments on commit 34677ef

Please sign in to comment.