-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
quoted = true | ||
v = string(body[i-1:start]) + v | ||
break | ||
} else if body[i] != ' ' { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
jobspec2/types.config.go
Outdated
v += "}" | ||
|
||
// find the start of inclusing "${..}" if it's inclused in one; otherwise, wrap it in one | ||
quoted := false |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.
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. |
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 asvalue = "${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.