From deed85ceeea1307800ff63b352edceaf47d261bd Mon Sep 17 00:00:00 2001 From: Zhangyang Huang <73207840+lanyeeee@users.noreply.github.com> Date: Fri, 20 Oct 2023 00:14:04 +0800 Subject: [PATCH] Fix potential null value issue in MergeDefaultConfig (#29) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix potential null value issue in MergeDefaultConfig * 🔧 Simplify default config value assignment Simplify the assignment of default configuration values by removing unnecessary conditional checks. This change improves code readability and reduces complexity. --------- Co-authored-by: Lee Miller --- apps/SKonsole/ConfigurationProvider.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/SKonsole/ConfigurationProvider.cs b/apps/SKonsole/ConfigurationProvider.cs index 209caa2..68a8d8c 100644 --- a/apps/SKonsole/ConfigurationProvider.cs +++ b/apps/SKonsole/ConfigurationProvider.cs @@ -35,10 +35,9 @@ private void MergeDefaultConfig() }; bool hasChanged = false; - foreach (var defaultConfigItem in defaultConfig) { - if (string.IsNullOrWhiteSpace(this._config[defaultConfigItem.Key])) + if (!this._config.TryGetValue(defaultConfigItem.Key, out string? value) || string.IsNullOrWhiteSpace(value)) { this._config[defaultConfigItem.Key] = defaultConfigItem.Value; hasChanged = true;