File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -121,7 +121,12 @@ func (s *OptionSet) ParseEnv(vs []EnvVar) error {
121
121
}
122
122
123
123
envVal , ok := envs [opt .Env ]
124
- if ! ok {
124
+ // Currently, empty values are treated as if the environment variable is
125
+ // unset. This behavior is technically not correct as there is now no
126
+ // way for a user to change a Default value to an empty string from
127
+ // the environment. Unfortunately, we have old configuration files
128
+ // that rely on the faulty behavior.
129
+ if ! ok || envVal == "" {
125
130
continue
126
131
}
127
132
Original file line number Diff line number Diff line change @@ -93,4 +93,26 @@ func TestOptionSet_ParseEnv(t *testing.T) {
93
93
require .NoError (t , err )
94
94
require .EqualValues (t , "foo" , workspaceName )
95
95
})
96
+
97
+ t .Run ("EmptyValue" , func (t * testing.T ) {
98
+ t .Parallel ()
99
+
100
+ var workspaceName clibase.String
101
+
102
+ os := clibase.OptionSet {
103
+ clibase.Option {
104
+ Name : "Workspace Name" ,
105
+ Value : & workspaceName ,
106
+ Default : "defname" ,
107
+ Env : "WORKSPACE_NAME" ,
108
+ },
109
+ }
110
+
111
+ err := os .SetDefaults ()
112
+ require .NoError (t , err )
113
+
114
+ err = os .ParseEnv (clibase .ParseEnviron ([]string {"CODER_WORKSPACE_NAME=" }, "CODER_" ))
115
+ require .NoError (t , err )
116
+ require .EqualValues (t , "defname" , workspaceName )
117
+ })
96
118
}
You can’t perform that action at this time.
0 commit comments