Skip to content

Commit

Permalink
Bug fix:Env File Feature would not accept = in value
Browse files Browse the repository at this point in the history
  • Loading branch information
ubhattacharjya committed Jun 19, 2020
1 parent 447c557 commit 106ed6f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion agent/taskresource/envFiles/envfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ func (envfile *EnvironmentFileResource) readEnvVarsFromFile(envfilePath string)
}
// only read the line that has "="
if strings.Contains(line, envVariableDelimiter) {
variables := strings.Split(line, "=")
variables := strings.SplitN(line, envVariableDelimiter, 2)
// verify that there is at least a character on each side
if len(variables[0]) > 0 && len(variables[1]) > 0 {
envVars[variables[0]] = variables[1]
Expand Down
10 changes: 7 additions & 3 deletions agent/taskresource/envFiles/envfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ func TestReadEnvVarsFromEnvfiles(t *testing.T) {
envfileResource := newMockEnvfileResource(envfiles, nil, nil, mockIOUtil)
envfileResource.bufio = mockBufio

envfileContent := "key=value"
envfileContentLine1 := "key1=value"
envFileContentLine2 := "key2=val1=val2"

tempOpen := open
open = func(name string) (oswrapper.File, error) {
Expand All @@ -325,7 +326,9 @@ func TestReadEnvVarsFromEnvfiles(t *testing.T) {
gomock.InOrder(
mockBufio.EXPECT().NewScanner(mockFile).Return(mockScanner),
mockScanner.EXPECT().Scan().Return(true),
mockScanner.EXPECT().Text().Return(envfileContent),
mockScanner.EXPECT().Text().Return(envfileContentLine1),
mockScanner.EXPECT().Scan().Return(true),
mockScanner.EXPECT().Text().Return(envFileContentLine2),
mockScanner.EXPECT().Scan().Return(false),
mockScanner.EXPECT().Err().Return(nil),
)
Expand All @@ -334,7 +337,8 @@ func TestReadEnvVarsFromEnvfiles(t *testing.T) {

assert.Nil(t, err)
assert.Equal(t, 1, len(envVarsList))
assert.Equal(t, "value", envVarsList[0]["key"])
assert.Equal(t, "value", envVarsList[0]["key1"])
assert.Equal(t, "val1=val2", envVarsList[0]["key2"])
}

func TestReadEnvVarsCommentFromEnvfiles(t *testing.T) {
Expand Down

0 comments on commit 106ed6f

Please sign in to comment.