mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-07 02:48:27 +08:00
fix(hcl): coerce non-string object keys to strings instead of panicking (#2795)
HCL object keys may be non-string literals (e.g. a number like 1). The decoder called cty.Value.AsString on the evaluated key, which panics with 'not a string' for any non-string key type. Mirror OpenTofu/Terragrunt by silently converting non-string keys to their string representation via cty/convert. Add decode scenarios covering numeric and boolean keys.
This commit is contained in:
@@ -472,6 +472,20 @@ var hclFormatScenarios = []formatScenario{
|
||||
expected: "service {\n optional_field = null\n}\n",
|
||||
scenarioType: "roundtrip",
|
||||
},
|
||||
{
|
||||
description: "Non-string object keys are coerced to strings",
|
||||
skipDoc: true,
|
||||
input: `intdict = { 1 = {} }`,
|
||||
expected: "intdict: {\"1\": {}}\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
description: "Mixed non-string object keys are coerced to strings",
|
||||
skipDoc: true,
|
||||
input: `d = { 1 = "a", 2 = "b", true = "c" }`,
|
||||
expected: "d: {\"1\": \"a\", \"2\": \"b\", \"true\": \"c\"}\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
}
|
||||
|
||||
func testHclScenario(t *testing.T, s formatScenario) {
|
||||
|
||||
Reference in New Issue
Block a user