mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-01 14:14:52 +08:00
Merge master into fix/hcl-nonstring-key-panic-2795
Resolve conflict in decoder_hcl.go by keeping typed object keys via convertCtyValueToNode (preserves int/bool/float keys in YAML) rather than coercing all keys to strings. Retain PR test case for integer key with empty object value, adapted to typed key output. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+37
-9
@@ -176,6 +176,41 @@ var hclFormatScenarios = []formatScenario{
|
||||
expected: "obj: {a: 1, b: \"two\"}\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
description: "object with integer keys",
|
||||
skipDoc: true,
|
||||
input: `obj = { 1 = "one", 2 = "two" }`,
|
||||
expected: "obj: {1: \"one\", 2: \"two\"}\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
description: "object with boolean keys",
|
||||
skipDoc: true,
|
||||
input: `obj = { (true) = "yes", (false) = "no" }`,
|
||||
expected: "obj: {true: \"yes\", false: \"no\"}\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
description: "object with float keys",
|
||||
skipDoc: true,
|
||||
input: `obj = { (3.14) = "pi" }`,
|
||||
expected: "obj: {3.14: \"pi\"}\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
description: "object with mixed scalar keys",
|
||||
skipDoc: true,
|
||||
input: `obj = { a = 1, 1 = "one", (true) = "yes" }`,
|
||||
expected: "obj: {a: 1, 1: \"one\", true: \"yes\"}\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
description: "nested object with integer keys",
|
||||
skipDoc: true,
|
||||
input: `config = { levels = { 1 = "debug", 2 = "info" } }`,
|
||||
expected: "config: {levels: {1: \"debug\", 2: \"info\"}}\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
{
|
||||
description: "nested block",
|
||||
skipDoc: true,
|
||||
@@ -473,17 +508,10 @@ var hclFormatScenarios = []formatScenario{
|
||||
scenarioType: "roundtrip",
|
||||
},
|
||||
{
|
||||
description: "Non-string object keys are coerced to strings",
|
||||
description: "object with integer key and empty value",
|
||||
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",
|
||||
expected: "intdict: {1: {}}\n",
|
||||
scenarioType: "decode",
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user