Skip to content

Commit

Permalink
Improve split key=value
Browse files Browse the repository at this point in the history
  • Loading branch information
thohng committed May 14, 2024
1 parent 96c6df0 commit 3f4aa7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/NetLah.Extensions.Configuration/MapConfigurationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ private void InternalLoad()
void TryParse(string keyValue)
{
var pos = keyValue.IndexOf('=');
var key1 = keyValue[..pos];
var key2 = keyValue[(pos + 1)..];
if (configuration[key1] is { } value)
if (pos > 0 && pos < keyValue.Length - 1)
{
Data[key2] = value;
var key1 = keyValue[..pos];
var key2 = keyValue[(pos + 1)..];
if (configuration[key1] is { } value)
{
Data[key2] = value;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ private void InternalLoad()
void TryParse(string prefix, string keyValue)
{
var pos = keyValue.IndexOf('=');
var key = keyValue[..pos];
var value = keyValue[(pos + 1)..];
Data[prefix + key] = value;
if (pos > 0 && pos < keyValue.Length - 1)
{
var key = keyValue[..pos];
var value = keyValue[(pos + 1)..];
Data[prefix + key] = value;
}
}
}
}

0 comments on commit 3f4aa7e

Please sign in to comment.