`MyIni.DeleteSection(section)` does not remove the section's keys
Description: `MyIni.DeleteSection` removes the section from the section list, then removes keys whose name equals the section name (`key.NameSegment.EqualsIgnoreCase(section)`) instead of whose section equals it (`key.SectionSegment`). The section's actual keys remain in the ini. Re-adding the section (via `Set`/`AddSection`) resurrects the stale keys, so "replace whole section" logic silently accumulates duplicates.
Real-world impact: PB scripts that store data by rewriting a section each save (`DeleteSection` + `Set` per key) keep every old key forever.
Repro (paste into any PB; the result is an echo, visible on the PB terminal immediately after compile):
public Program()
{
var ini = new MyIni();
ini.Set("Values", "100", "ValueA");
ini.Set("Values", "200", "ValueB");
ini.DeleteSection("Values");
var keys = new List<MyIniKey>();
ini.GetKeys("Values", keys);
ini.Set("Values", "300", "ValueC");
var sb = new StringBuilder();
sb.AppendLine($"DeleteSection(\"Values\") left {keys.Count} of 2 keys behind:");
foreach (var key in keys)
{
sb.AppendLine($" {key}");
}
sb.AppendLine();
sb.AppendLine("Expected after DeleteSection: section gone, 0 keys.");
sb.AppendLine($"Actual ini after re-populating the section (stale keys are back):");
sb.Append(ini.ToString());
Echo(sb.ToString());
}
public void Main(string argument, UpdateType source)
{
}
public void Save()
{
} Expected output: `left 0 of 2 keys behind`, final ini `[Values] 300=ValueC`.
Actual: `left 2 of 2 keys behind: Values/100, Values/200`, final ini contains `100=ValueA`, `200=ValueB` (stale) and `300=ValueC`.
Suggested fix: in `MyIni.DeleteSection`, `key.NameSegment` → `key.SectionSegment`.
I have the same bug
Replies have been locked on this page!