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

hcl2: handle unquoted undefined variables #10419

Merged
merged 2 commits into from
Apr 21, 2021
Merged

Conversation

notnoop
Copy link
Contributor

@notnoop notnoop commented Apr 21, 2021

This fixes a regression in #10326, to handle unquoted unknown variables.

The HCL job may contain unquoted undefined variable references without ${...} wrapping, e.g. value = meta.node_class. In 1.0.4, this got parsed as value = "${meta.node_class}".

This code performs a scan to find the relevant ${ and }, and only tries to find the closest ones with whitespace as the only separator.

quoted = true
v = string(body[i-1:start]) + v
break
} else if body[i] != ' ' {
Copy link
Member

Choose a reason for hiding this comment

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

Should we being using unicode.IsSpace to catch other whitespace chars?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing emprically, only a plain space works. Trying with any other (e.g. \t, \n, etc) I get an error like the following:

input.hcl:2,23-24: Invalid character; This character is not used within the language.
input.hcl:2,23-24: Extra characters after interpolation expression; Expected a closing brace to end the interpolation expression, but found extra characters.

v += "}"

// find the start of inclusing "${..}" if it's inclused in one; otherwise, wrap it in one
quoted := false
Copy link
Member

Choose a reason for hiding this comment

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

I'm finding this a little hard to follow and maybe it's the name of this variable that's confusing me. Is this really only signifying "quoted" or is it doing double-duty for something like isBracketed as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bracketed is a better name - didn't know what to call it! Thanks!

Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

LGTM

@notnoop notnoop merged commit 6ab7f49 into main Apr 21, 2021
@notnoop notnoop deleted the b-unquoted-unknown-variables branch April 21, 2021 17:24
schmichael pushed a commit that referenced this pull request May 14, 2021
This fixes a regression in #10326, to handle unquoted unknown variables.

The HCL job may contain unquoted undefined variable references without ${...} wrapping, e.g. value = meta.node_class. In 1.0.4, this got parsed as value = "${meta.node_class}".

This code performs a scan to find the relevant ${ and }, and only tries to find the closest ones with whitespace as the only separator.
@tgross tgross added this to the 1.1.0 milestone May 17, 2021
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants