Skip to content

Commit fc812da

Browse files
Bug fix:Env File Feature would not accept = in value
1 parent 447c557 commit fc812da

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

agent/taskresource/envFiles/envfile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ func (envfile *EnvironmentFileResource) readEnvVarsFromFile(envfilePath string)
559559
}
560560
// only read the line that has "="
561561
if strings.Contains(line, envVariableDelimiter) {
562-
variables := strings.Split(line, "=")
562+
variables := strings.SplitN(line, "=", 2)
563563
// verify that there is at least a character on each side
564564
if len(variables[0]) > 0 && len(variables[1]) > 0 {
565565
envVars[variables[0]] = variables[1]

agent/taskresource/envFiles/envfile_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ func TestReadEnvVarsFromEnvfiles(t *testing.T) {
313313
envfileResource := newMockEnvfileResource(envfiles, nil, nil, mockIOUtil)
314314
envfileResource.bufio = mockBufio
315315

316-
envfileContent := "key=value"
316+
envfileContent := "key1=value"
317+
envFileContentLine2 := "key2=val1=val2"
317318

318319
tempOpen := open
319320
open = func(name string) (oswrapper.File, error) {
@@ -326,6 +327,8 @@ func TestReadEnvVarsFromEnvfiles(t *testing.T) {
326327
mockBufio.EXPECT().NewScanner(mockFile).Return(mockScanner),
327328
mockScanner.EXPECT().Scan().Return(true),
328329
mockScanner.EXPECT().Text().Return(envfileContent),
330+
mockScanner.EXPECT().Scan().Return(true),
331+
mockScanner.EXPECT().Text().Return(envFileContentLine2),
329332
mockScanner.EXPECT().Scan().Return(false),
330333
mockScanner.EXPECT().Err().Return(nil),
331334
)
@@ -334,7 +337,8 @@ func TestReadEnvVarsFromEnvfiles(t *testing.T) {
334337

335338
assert.Nil(t, err)
336339
assert.Equal(t, 1, len(envVarsList))
337-
assert.Equal(t, "value", envVarsList[0]["key"])
340+
assert.Equal(t, "value", envVarsList[0]["key1"])
341+
assert.Equal(t, "val1=val2", envVarsList[0]["key2"])
338342
}
339343

340344
func TestReadEnvVarsCommentFromEnvfiles(t *testing.T) {

0 commit comments

Comments
 (0)