Skip to content

HOCON adapter: ExpandKeys errors when key length == 0 #631

@Aaronontheweb

Description

@Aaronontheweb

Version Information
Version of Akka.NET? Akka.Hosting
Which Akka.NET Modules? at least v1.5.44, if not earlier

Describe the bug

private static HoconValue ExpandKey(this IConfigurationSection config, HoconObject parent, bool normalizeKeys)
{
// Sanitize configuration brought in from environment variables,
// "__" are already converted to ":" by the environment configuration provider.
var sanitized = (normalizeKeys ? config.Key.ToLowerInvariant() : config.Key).Replace("_", "-");
var keys = sanitized.SplitDottedPathHonouringQuotes().ToList();
// No need to expand the chain
if (keys.Count == 1)
{
return parent.GetOrCreateKey(keys[0]);
}
var currentObj = parent;
while (keys.Count > 1)
{
var key = keys.Pop();
var currentValue = currentObj.GetOrCreateKey(key);
if (currentValue.IsObject())
{
currentObj = currentValue.GetObject();
}
else
{
currentObj = new HoconObject();
currentValue.AppendValue(currentObj);
}
}
return currentObj.GetOrCreateKey(keys[0]);
}

If keys.length == 0, that scenario is unhandled inside this method and we try to access keys[0], which results in an IndexOutOfRange exception.

This behavior appears to be dependent on the types of environment variables that are present - in my case, it's these ones:

Image

Expected behavior

Parser should not die on IConfigurationSection instances that have no key / path.

Actual behavior

Throws an IndexOutOfRange exception currently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions