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

substr("x", 0, 0) returns "x" instead of "" #24318

Closed
alexyakunin opened this issue Mar 8, 2020 · 4 comments · Fixed by #24621
Closed

substr("x", 0, 0) returns "x" instead of "" #24318

alexyakunin opened this issue Mar 8, 2020 · 4 comments · Fixed by #24621

Comments

@alexyakunin
Copy link

alexyakunin commented Mar 8, 2020

It seems substr assumes the whole string tail must be returned when the last argument is zero:

terraform console
> substr("abc", 0, 0)
abc
> substr("abc", 1, 0)
bc

This behavior isn't described in the documentation; moreover, it seems this can lead to a number of issues when the length of a substring is computed rather than pre-defined.

@nick96
Copy link

nick96 commented Mar 9, 2020

I'm interested in contributing to terraform and thought this issue looked good (hope that's okay!). Looks like this is an issue in zclconf/go-cty. I've submitted a patch there (again, hope that's okay!)

@nick96
Copy link

nick96 commented Mar 10, 2020

My upstream patch got merged. They're not ready to release a new version of go-cty and there's also the issue of this potentially being a breaking change (?)

@alisdair
Copy link
Contributor

Hi @nick96! The go-cty release has been pulled into master now, so this fix will go out as part of 0.13. Thanks for your contribution!

@ghost
Copy link

ghost commented May 14, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators May 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants