Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public static IDictionary<string, string> Read(Stream stream)
{
// remove the brackets
#if NET
sectionPrefix = string.Concat(line.AsSpan(1, line.Length - 2), ConfigurationPath.KeyDelimiter);
sectionPrefix = string.Concat(line.AsSpan(1, line.Length - 2).Trim(), ConfigurationPath.KeyDelimiter);
#else
sectionPrefix = line.Substring(1, line.Length - 2) + ConfigurationPath.KeyDelimiter;
sectionPrefix = line.Substring(1, line.Length - 2).Trim() + ConfigurationPath.KeyDelimiter;
#endif
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,28 @@ public void SupportAndIgnoreComments()
Assert.Equal("MySql", iniConfigSrc.Get("Data:Inventory:Provider"));
}

[Fact]
public void ShouldRemoveLeadingAndTrailingWhiteSpacesFromKeyAndValue()
{
var ini = "[section]\n" +
" \t key \t = \t value\t ";
var iniConfigSrc = new IniConfigurationProvider(new IniConfigurationSource());
iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini));

Assert.Equal("value", iniConfigSrc.Get("section:key"));
}

[Fact]
public void ShouldRemoveLeadingAndTrailingWhiteSpacesFromSectionName()
{
var ini = "[ \t section \t ]\n" +
"key=value";
var iniConfigSrc = new IniConfigurationProvider(new IniConfigurationSource());
iniConfigSrc.Load(TestStreamHelpers.StringToStream(ini));

Assert.Equal("value", iniConfigSrc.Get("section:key"));
}

[Fact]
public void ThrowExceptionWhenFoundInvalidLine()
{
Expand Down