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 Substr function call with length argument of zero to return "" #48

Merged
merged 1 commit into from
Mar 9, 2020

Conversation

nick96
Copy link
Contributor

@nick96 nick96 commented Mar 9, 2020

This issue was raised in terraform (hashicorp/terraform#24318) and it looks like it's a bug in stdlib.SubstrFunc's impl where the substr function returns the whole string then the length argument is 0.

I've got a fix which is hopefully useful, I thought that it'd be best to have the length check as high up as it can but there may be other factors I'm not considering (I've run the test suite and it's passing).

@codecov
Copy link

codecov bot commented Mar 9, 2020

Codecov Report

Merging #48 into master will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #48      +/-   ##
==========================================
+ Coverage   70.11%   70.21%   +0.09%     
==========================================
  Files          78       78              
  Lines        7078     7080       +2     
==========================================
+ Hits         4963     4971       +8     
+ Misses       1672     1666       -6     
  Partials      443      443
Impacted Files Coverage Δ
cty/function/stdlib/string.go 41.05% <100%> (+0.62%) ⬆️
cty/convert/compare_types.go 100% <0%> (+7.14%) ⬆️

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 50eb240...926cb9c. Read the comment docs.

@apparentlymart
Copy link
Collaborator

Thanks for looking into this, @nick96!

This fix looks good to me, and I'm going to merge it now. I suppose for the downstream Terraform issue the next step here would be to open a PR including an upgraded version of cty containing this fix. I'm intending to hold for a little longer before cutting the next cty release in case there are other changes to include in it, because the previous release was only last week, but one of the other changes awaiting release is also partially motivated by work in Terraform so we can resolve them both at once with a single PR to Terraform once that release is tagged.

I expect that from Terraform's perspective this fix could be considered as a breaking change to its configuration language (in case someone is already relying on zero being interpreted as "the remainder of the string").

@apparentlymart apparentlymart merged commit 9ae7dd9 into zclconf:master Mar 9, 2020
@nick96
Copy link
Contributor Author

nick96 commented Mar 10, 2020

Awesome! I'll raise the next steps issue on the Terraform issue,

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.

2 participants