Commit 5e4a386
Fix issue where terminal environment variables are not removed when they are commented out or deleted from .env files. (#1131)
Fixes #936
The problem this PR fixed is when users comment out or remove a variable
from their .env file:
```
API_KEY=secret
# DEBUG=true ← commented out
```
The DEBUG variable remained in terminal environments because:
1. `dotenv.parse()` ignores commented lines (seems the right behavior
per dotenv spec)
2. The returned object only contained active variables: `{ API_KEY:
'secret' }`
3. The old code only iterated over keys in `envVars` and it never saw
`DEBUG`
4. The `delete()` call was never reached for removed/commented variables
Solution is to call `clear()` before re-injecting variables, which makes
the fix stays at the terminal injection layer rather than modifying the
parsing layer, avoiding impacting on other consumers.
I also noticed some other issues with setting watcher, currently there's
no file watcher watching the settings change, so a reload will be
required when toggling the setting. We can consider adding a config
listener.
---------
Co-authored-by: Anthony Kim <62267334+anthonykim1@users.noreply.github.com>1 parent 1f7b7ef commit 5e4a386
1 file changed
+45
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
134 | 136 | | |
135 | 137 | | |
136 | 138 | | |
| 139 | + | |
| 140 | + | |
137 | 141 | | |
138 | 142 | | |
139 | 143 | | |
| |||
149 | 153 | | |
150 | 154 | | |
151 | 155 | | |
| 156 | + | |
| 157 | + | |
152 | 158 | | |
153 | 159 | | |
154 | 160 | | |
| |||
165 | 171 | | |
166 | 172 | | |
167 | 173 | | |
168 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
169 | 177 | | |
170 | 178 | | |
171 | | - | |
172 | | - | |
173 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
174 | 189 | | |
175 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
176 | 196 | | |
| 197 | + | |
177 | 198 | | |
178 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
179 | 203 | | |
180 | 204 | | |
181 | 205 | | |
| |||
212 | 236 | | |
213 | 237 | | |
214 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
215 | 255 | | |
0 commit comments