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

templateargs: Deal with YAML's handling of "y" as boolean #254

Merged
merged 2 commits into from
Apr 16, 2019

Conversation

prashantv
Copy link
Contributor

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

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
@codecov
Copy link

codecov bot commented Apr 16, 2019

Codecov Report

Merging #254 into dev will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #254      +/-   ##
==========================================
+ Coverage   94.04%   94.09%   +0.05%     
==========================================
  Files          43       43              
  Lines        2366     2371       +5     
==========================================
+ Hits         2225     2231       +6     
+ Misses         88       87       -1     
  Partials       53       53
Impacted Files Coverage Δ
templateargs/process.go 100% <100%> (ø) ⬆️
templateargs/interpolate/parse.go 90.59% <0%> (+0.49%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0f1beae...c212ad6. Read the comment docs.

@prashantv prashantv merged commit a02e823 into dev Apr 16, 2019
@prashantv prashantv deleted the template_bool branch April 16, 2019 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Avoid yaml Marshal and Unmarshal when processing yab templates
2 participants