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(file) convert yaml to JSON #229

Merged
merged 1 commit into from
Nov 10, 2020
Merged

fix(file) convert yaml to JSON #229

merged 1 commit into from
Nov 10, 2020

Conversation

hbagdi
Copy link
Member

@hbagdi hbagdi commented Nov 9, 2020

go-yaml marshals into map[interface{}]interface{}.
This change ensures that map[interface{}]interface{} is converted into
map[string]interface{} RECURSIVELY.

This patch needs tests before it can be merged. Added a test.

See #144

@hbagdi hbagdi force-pushed the fix/144 branch 2 times, most recently from 421ea6c to a3e2b5e Compare November 9, 2020 17:06
@hbagdi hbagdi marked this pull request as ready for review November 9, 2020 17:07
Copy link
Contributor

@mflendrich mflendrich left a comment

Choose a reason for hiding this comment

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

LGTM but see comments, feel free to merge after resolution

file/readfile.go Outdated
// yamlUnmarshal is a wrapper around yaml.Unmarshal to ensure that the right
// yaml package is in use. The verification for this is done using a test.
func yamlUnmarshal(bytes []byte, v interface{}) error {
return yaml.Unmarshal(bytes, v)
Copy link
Contributor

Choose a reason for hiding this comment

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

optional suggestion: import by a nonstardard name, e.g. ghodssyaml, to make it harder for goimports to tamper with this import

file/readfile.go Outdated
if err != nil {
return nil, err
}
return &content, nil
}

// yamlUnmarshal is a wrapper around yaml.Unmarshal to ensure that the right
// yaml package is in use. The verification for this is done using a test.
Copy link
Contributor

Choose a reason for hiding this comment

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

please explain (to the future reader) what behavior is desired (and what is undesired) from this function.

`go-yaml` marshals into `map[interface{}]interface{}`.
This change ensures that `map[interface{}]interface{}` is converted into
`map[string]interface{}` RECURSIVELY.

See #144
Copy link
Contributor

@rainest rainest left a comment

Choose a reason for hiding this comment

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

Tested against my local environment and confirmed that the example provided by #144 now successfully restores/doesn't delete itself on subsequent sync.

Explanation covers the high level reason for the YAML parser not creating a map that the JSON parser can then unmarshal successfully later.

@hbagdi hbagdi merged commit c359633 into main Nov 10, 2020
@hbagdi hbagdi deleted the fix/144 branch November 10, 2020 14:32
rainest pushed a commit that referenced this pull request Apr 21, 2021
`go-yaml` marshals into `map[interface{}]interface{}`.
This change ensures that `map[interface{}]interface{}` is converted into
`map[string]interface{}` RECURSIVELY.

See #144
From #229
AntoineJac pushed a commit that referenced this pull request Jan 23, 2024
`go-yaml` marshals into `map[interface{}]interface{}`.
This change ensures that `map[interface{}]interface{}` is converted into
`map[string]interface{}` RECURSIVELY.

See #144
From #229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants