Fix handling of empty settings (#18131)

This commit is contained in:
christine betts
2026-02-03 15:39:20 -05:00
committed by GitHub
parent 2cf3a14439
commit 3e954930f1
9 changed files with 83 additions and 13 deletions
@@ -786,6 +786,23 @@ describe('extensionSettings', () => {
expect(await userKeychain.getSecret('VAR2')).toBeNull();
});
it('should delete a non-sensitive setting if the new value is empty', async () => {
mockRequestSetting.mockResolvedValue('');
await updateSetting(
config,
'12345',
'VAR1',
mockRequestSetting,
ExtensionSettingScope.USER,
tempWorkspaceDir,
);
const expectedEnvPath = path.join(extensionDir, '.env');
const actualContent = await fsPromises.readFile(expectedEnvPath, 'utf-8');
expect(actualContent).not.toContain('VAR1=');
});
it('should not throw if deleting a non-existent sensitive setting with empty value', async () => {
mockRequestSetting.mockResolvedValue('');
// Ensure it doesn't exist first
@@ -251,7 +251,11 @@ export async function updateSetting(
}
const parsedEnv = dotenv.parse(envContent);
parsedEnv[settingToUpdate.envVar] = newValue;
if (!newValue) {
delete parsedEnv[settingToUpdate.envVar];
} else {
parsedEnv[settingToUpdate.envVar] = newValue;
}
// We only want to write back the variables that are not sensitive.
const nonSensitiveSettings: Record<string, string> = {};