IndexOutOfRangeException in HandlebarsDotNet.PathStructure.PathResolver.ResolvePath for nested object path block expression
See original GitHub issueDescribe the bug
Trying to enumerate an array via a nested object path:
{{#bundles.styles.vendor}}{{this}}{{/bundles.styles.vendor}}
Results in an IndexOutOfRangeException exception.
Expected behavior:
I would expect the same result as when not using a nested path, i.e.
{{#arr}}....{/arr}}
Or, alternatively, if this is not supported: a clearer exception message.
Test to reproduce
var context = new
{
bundles = new
{
styles = new
{
vendor = new[] { "a", "b", "c" }
}
},
arr = new[] { "d", "e", "f"}
};
// Works: Output = "abc"
Handlebars.Compile("{{#each bundles.styles.vendor}}{{this}}{{/each}}")(context).Dump();
// Works: Output = "def"
Handlebars.Compile("{{#arr}}{{this}}{{/arr}}")(context).Dump();
// Fails: IndexOutOfRangeException in HandlebarsDotNet.PathStructure.PathResolver.ResolvePath
// On line #36: if (!TryResolveValue(pathInfo.IsVariable, context, pathChain[0], instance, out instance))
Handlebars.Compile("{{#bundles.styles.vendor}}{{this}}{{/bundles.styles.vendor}}")(context).Dump();```
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Handlebars.Net
IndexOutOfRangeException in HandlebarsDotNet.PathStructure.PathResolver.ResolvePath for nested ... Trying to enumerate an array via a nested object path:
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Will do as soon as I have some spare time, and yes, I noticed I can do continue; in the loop instead of prefiltering them.
@aslezak , it’s hard to tell without testing. I’d really appreciate if you can have a look closer.
nit: Try to avoid Linq as this is performance critical path. In this case the check can be placed inside of
for
that is right below the line you mentioned.