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

Avoid yaml Marshal and Unmarshal when processing yab templates #253

Closed
prashantv opened this issue Apr 16, 2019 · 0 comments · Fixed by #254
Closed

Avoid yaml Marshal and Unmarshal when processing yab templates #253

prashantv opened this issue Apr 16, 2019 · 0 comments · Fixed by #254

Comments

@prashantv
Copy link
Contributor

This can cause unexpected issues when using keys like "y" which get treated as a boolean by yaml.v2.

yaml.v3 avoids this issue too.

prashantv added a commit that referenced this issue Apr 16, 2019
When using yab templates and a key is specified as `"y"` (with quoting),
the template parsing ends up converting this to `y`, which then gets
unmarshalled as a boolean. The underlying cause is:
go-yaml/yaml#214

This is caused by template rendering's use of `yaml.Unmarshal` on all
string values which can lose the type.

This change restricts the `Unmarshal` to values that were modified
as part of the rendering step. It also adds special logic to protect
against YAML's boolean handling, by only using the boolean value
if strconv.ParseBool would parse the value. This means if a value
was rendered as `y`, we would still not treat it as a boolean.

Fixes #253
prashantv added a commit that referenced this issue Apr 16, 2019
When using yab templates and a key is specified as `"y"` (with quoting),
the template parsing ends up converting this to `y`, which then gets
unmarshalled as a boolean. The underlying cause is:
go-yaml/yaml#214

This is caused by template rendering's use of `yaml.Unmarshal` on all
string values which can lose the type.

This change restricts the `Unmarshal` to values that were modified
as part of the rendering step. It also adds special logic to protect
against YAML's boolean handling, by only using the boolean value
if strconv.ParseBool would parse the value. This means if a value
was rendered as `y`, we would still not treat it as a boolean.

Fixes #253
prashantv added a commit that referenced this issue Apr 16, 2019
When using yab templates and a key is specified as `"y"` (with quoting),
the template parsing ends up converting this to `y`, which then gets
unmarshalled as a boolean. The underlying cause is:
go-yaml/yaml#214

This is caused by template rendering's use of `yaml.Unmarshal` on all
string values which can lose the type.

This change restricts the `Unmarshal` to values that were modified
as part of the rendering step. It also adds special logic to protect
against YAML's boolean handling, by only using the boolean value
if strconv.ParseBool would parse the value. This means if a value
was rendered as `y`, we would still not treat it as a boolean.

Fixes #253
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant