Skip to content

Commit 8b8821a

Browse files
committed
Ensure consistent behavior by restricting UpdateConfigSettingWithAppSettings() to LazyInit or later.
1 parent 50c3b1b commit 8b8821a

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/Base/KeyValueConfigBuilder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public abstract class KeyValueConfigBuilder : ConfigurationBuilder
2727

2828
private NameValueCollection _config = null;
2929
private IDictionary<string, string> _cachedValues;
30+
private bool _lazyInitializeStarted = false;
3031
private bool _lazyInitialized = false;
3132
private bool _greedyInitialized = false;
3233
private bool _inAppSettings = false;
@@ -107,6 +108,7 @@ public override void Initialize(string name, NameValueCollection config)
107108
protected virtual void LazyInitialize(string name, NameValueCollection config)
108109
{
109110
// Use pre-assigned defaults if not specified. Non-freeform options should throw on unrecognized values.
111+
_lazyInitializeStarted = true;
110112
_tokenPattern = config[tokenPatternTag] ?? _tokenPattern;
111113
_keyPrefix = UpdateConfigSettingWithAppSettings(prefixTag) ?? _keyPrefix;
112114
_stripPrefix = (UpdateConfigSettingWithAppSettings(stripPrefixTag) != null) ? Boolean.Parse(config[stripPrefixTag]) : _stripPrefix;
@@ -125,7 +127,7 @@ protected string UpdateConfigSettingWithAppSettings(string configName)
125127
{
126128
string configValue = _config[configName];
127129

128-
if (String.IsNullOrWhiteSpace(configValue))
130+
if (!_lazyInitializeStarted || String.IsNullOrWhiteSpace(configValue))
129131
return configValue;
130132

131133
// If we are processing appSettings in ProcessConfigurationSection(), then we can use that. Other config builders in

0 commit comments

Comments
 (0)