Handlebars-Net / Handlebars.Net

A real .NET Handlebars engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Value of Dictionary<object, object> doesn't resolve unless keys are all lower case

alexwiese opened this issue · comments

Describe the bug

Example:

Handlebars.Net 2.1.4

Given a Dictionary<object, object> only keys that are lower case are resolved:
image

Expected behavior:

The values can be resolved using keys that contain upper case letters.

Test to reproduce

var input = new Dictionary<object, object> 
{
	["foo"] = "123",
	["FooBar"] = "456",
	["barFoo"] = "789"
};

var template = """
- {Foo} => {{Foo}}
- {foo} => {{foo}}
- {fooBar} => {{fooBar}}
- {FooBar} => {{FooBar}}
- {barFoo} => {{barFoo}}
""";

Handlebars.Compile(template)(input);

Other related info

Looks like it's related to this code which always uses memberName.LowerInvariant.
Is there a reason it's always converted to lower case before accessing the value?
Is a special case needed for Dictionary<object, TValue> to handle this?

This is expected behavior. It is handler in a different class (see GenericDictionaryAccessor). This happens because value resolution is forwarded to dictionary directly and your dictionary handles keys in case-sensitive way.

It’s expected that value resolution fails even if the correct key is provided (with matching casing)?