fix(dict): support generic map types in keys, values, hasKey, pick, omit#2
Open
bejaratommy wants to merge 1 commit intomasterfrom
Open
fix(dict): support generic map types in keys, values, hasKey, pick, omit#2bejaratommy wants to merge 1 commit intomasterfrom
bejaratommy wants to merge 1 commit intomasterfrom
Conversation
The keys, values, hasKey, pick, and omit functions previously only
accepted map[string]interface{}. This caused a runtime panic when any
other map type (e.g. map[string]string, map[string]int) was passed.
Use reflect to accept any map with string keys, converting values to
interface{} for the returned collections. Non-map inputs are silently
ignored, consistent with how the rest of the dict functions handle
bad input in templates.
Fixes Masterminds#455
Signed-off-by: Tommy <tommy@bejara.net>
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.
Summary
Fixes Masterminds#455 (upstream: Masterminds#455)
The
keys,values,hasKey,pick, andomitfunctions previously only acceptedmap[string]interface{}. Passing any other map type (e.g.map[string]string,map[string]int) caused a template execution error.Changes
keys,values,hasKey,pick, andomitindict.goto usereflectto accept any map type whose key isstringinterface{}in returned collections, consistent with existing behaviormap[string]stringandmap[string]intTesting
All existing tests continue to pass. The only pre-existing failure is
TestRound(floating-point precision on this platform), which is unrelated to this change.