mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-07 12:07:42 +08:00
Merge pull request #1080 from jedevc/issue-1051
hclparser: strip out blocks for json files
This commit is contained in:
commit
9cdd837f6b
@ -745,3 +745,13 @@ target "two" {
|
|||||||
require.Equal(t, c.Targets[1].Name, "two")
|
require.Equal(t, c.Targets[1].Name, "two")
|
||||||
require.Equal(t, map[string]string{"b": "pre-jkl"}, c.Targets[1].Args)
|
require.Equal(t, map[string]string{"b": "pre-jkl"}, c.Targets[1].Args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEmptyVariableJSON(t *testing.T) {
|
||||||
|
dt := []byte(`{
|
||||||
|
"variable": {
|
||||||
|
"VAR": {}
|
||||||
|
}
|
||||||
|
}`)
|
||||||
|
_, err := ParseFile(dt, "docker-bake.json")
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
@ -256,6 +256,7 @@ func Parse(b hcl.Body, opt Opt, val interface{}) hcl.Diagnostics {
|
|||||||
if err := gohcl.DecodeBody(b, nil, &defs); err != nil {
|
if err := gohcl.DecodeBody(b, nil, &defs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defsSchema, _ := gohcl.ImpliedBodySchema(defs)
|
||||||
|
|
||||||
if opt.LookupVar == nil {
|
if opt.LookupVar == nil {
|
||||||
opt.LookupVar = func(string) (string, bool) {
|
opt.LookupVar = func(string) (string, bool) {
|
||||||
@ -300,6 +301,16 @@ func Parse(b hcl.Body, opt Opt, val interface{}) hcl.Diagnostics {
|
|||||||
p.funcs[v.Name] = v
|
p.funcs[v.Name] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content, b, diags := b.PartialContent(schema)
|
||||||
|
if diags.HasErrors() {
|
||||||
|
return diags
|
||||||
|
}
|
||||||
|
|
||||||
|
_, b, diags = b.PartialContent(defsSchema)
|
||||||
|
if diags.HasErrors() {
|
||||||
|
return diags
|
||||||
|
}
|
||||||
|
|
||||||
attrs, diags := b.JustAttributes()
|
attrs, diags := b.JustAttributes()
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
if d := removeAttributesDiags(diags, reserved, p.vars); len(d) > 0 {
|
if d := removeAttributesDiags(diags, reserved, p.vars); len(d) > 0 {
|
||||||
@ -371,11 +382,6 @@ func Parse(b hcl.Body, opt Opt, val interface{}) hcl.Diagnostics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
content, _, diags := b.PartialContent(schema)
|
|
||||||
if diags.HasErrors() {
|
|
||||||
return diags
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, a := range content.Attributes {
|
for _, a := range content.Attributes {
|
||||||
return hcl.Diagnostics{
|
return hcl.Diagnostics{
|
||||||
&hcl.Diagnostic{
|
&hcl.Diagnostic{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user