Repository navigation
JsonNodeValueResolver: resolve Map contexts (block parameters) (#983) - #1229
Merged
Merged
Conversation
JsonNodeValueResolver only handled JsonNode/ArrayNode contexts, so when a plain Map was pushed on the context stack (as each-block parameters are) it returned UNRESOLVED. End-to-end templates still worked because the context builder appends MapValueResolver, but the resolver itself could not look up a Map on its own. Handle Map contexts the same way MapValueResolver does in resolve(context, name), resolve(context) and propertySet(context). Applied to both the Jackson 2 and Jackson 3 resolvers, with a unit test for each. Fixes jknack#983 Signed-off-by: karma <inskarma0101@gmail.com>
Contributor
Author
|
Thanks for merging 🙏 |
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.
JsonNodeValueResolveronly handledJsonNode/ArrayNodecontexts. When a plainMapis pushed on the context stack — which is how{{#each xs as |value index|}}block parameters are stored — the resolver returnedUNRESOLVEDfor every key, andpropertySetreturned an empty set.End-to-end templates still rendered because
Context.Builder#resolver(...)appendsMapValueResolver, so theMapwas resolved by that fallback. But the resolver on its own could not look up aMap, which is what #983 reports.This mirrors
MapValueResolver'sMaphandling insideJsonNodeValueResolverforresolve(context, name),resolve(context)andpropertySet(context), so block parameters resolve even whenJsonNodeValueResolveris used withoutMapValueResolver.The same fix is applied to both the Jackson 2 (
handlebars-jackson) and Jackson 3 (handlebars-jackson3) resolvers, since they are kept in parallel.Testing
Added a
resolveMapunit test to each module'sJsonNodeValueResolverTest. Before the change it fails (expected: <0> but was: <...UNRESOLVED...>); after it passes.mvn testis green forhandlebars-jackson,handlebars-jackson3andtests(50 tests), andspotless:checkpasses with no new offenses.Fixes #983
Happy to adjust the approach if you'd prefer to resolve the
Mapvalues throughJsonNoderesolution instead of returning them as-is.