-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package jobspec2 | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"strings" | ||
|
||
|
@@ -315,18 +314,32 @@ func (c *jobConfig) EvalContext() *hcl.EvalContext { | |
end := t.SourceRange().End.Byte | ||
|
||
v := string(body[start:end]) | ||
if i := bytes.IndexByte(body[end:], '}'); i != -1 { | ||
v += string(body[end : end+i+1]) | ||
} else { | ||
// fallback for unexpected cases | ||
v += "}" | ||
|
||
// find the start of inclusing "${..}" if it's inclused in one; otherwise, wrap it in one | ||
quoted := false | ||
for i := start - 1; i >= 1; i-- { | ||
if body[i] == '{' && body[i-1] == '$' { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Should we being using There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
|
||
break | ||
} | ||
} | ||
|
||
if i := bytes.LastIndex(body[:start], []byte("${")); i != 0 { | ||
v = string(body[i:start]) + v | ||
if quoted { | ||
for i := end + 1; i < len(body); i++ { | ||
if body[i] == '}' { | ||
v += string(body[end:i]) | ||
} else if body[i] != ' ' { | ||
// unexpected! | ||
v += "}" | ||
break | ||
} | ||
} | ||
|
||
} else { | ||
// fallback for unexpected cases | ||
v = "${" + v | ||
v = "${" + v + "}" | ||
} | ||
|
||
return cty.StringVal(v), nil | ||
|
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!