Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #151
Fix Stubble section lambda context for primitive-scoped sections
Problem
When a 3-argument section lambda (
Func<dynamic, string, Func<string, string>, object>) is nested inside a boolean or other primitive-valued section, Stubble passes the primitive value (e.g.true) as the lambda's context argument instead of the actual data object. This causes the lambda to receive a useless value and fail to resolve any data paths.Example template structure that triggers the bug:
The
groupBylambda needs the parent data dictionary to resolve array paths, but receivestrueand produces empty output.Root Cause
In
SectionTokenRenderer, the lambda dispatch code passedcontext.Viewdirectly to dynamic-context lambdas. When rendering inside a boolean section like{{#ringProgression}}, the context is pushed with the boolean value, socontext.Viewistrue.Fix
Stubble.Core (
SectionTokenRenderer.cs)Added a
FindNearestObjectViewhelper that walks up the context parent chain, skipping primitive views (bool, int, long, float, double, decimal, string), and returns the nearest ancestor view that is a real object (dictionary, hashtable, etc.). BothWriteandWriteAsyncuse this instead ofcontext.Viewwhen dispatching to dynamic-context lambdas.When the lambda is inside an object section (e.g. a dictionary),
FindNearestObjectViewreturns that dictionary directly — preserving existing scoped behavior.