Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix fromJson template function deserializing non-objects #3380

Merged
merged 1 commit into from
Dec 1, 2023

Conversation

twpayne
Copy link
Owner

@twpayne twpayne commented Nov 30, 2023

Fixes #3379.

if err := chezmoi.FormatJSONC.Unmarshal([]byte(s), &value); err != nil {
panic(err)
}
return value
}

func (c *Config) fromTomlTemplateFunc(s string) any {
var value map[string]any
var value any
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that TOML allows anything but a dictionary at the root, so this is probably fine as it was.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed in e68328e.

if err := chezmoi.FormatTOML.Unmarshal([]byte(s), &value); err != nil {
panic(err)
}
return value
}

func (c *Config) fromYamlTemplateFunc(s string) any {
var value map[string]any
var value any
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably a good thing as

- 1
- 2
- 3

is a thing.

@halostatue
Copy link
Collaborator

This does fix the test case.

@twpayne twpayne merged commit 649c758 into master Dec 1, 2023
18 checks passed
@twpayne twpayne deleted the fix-3379 branch December 1, 2023 08:26
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fromJson regression in 2.42.x (it can no longer unmarshal arrays)
2 participants