Skip to content

Commit b144ad0

Browse files
denikclaude
andauthored
Fix SkipPrefix dropping value field in KeyValue nodes (#4478)
## Changes The SkipPrefix method was not copying the value field when creating new PathNodes, causing KeyValue nodes (e.g., `[task_key='my_task']`) to lose their value part. This would corrupt paths containing KeyValue nodes after calling SkipPrefix. ## Tests Unit tests. Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 848b359 commit b144ad0

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

libs/structs/structpath/path.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ func (p *PathNode) SkipPrefix(n int) *PathNode {
614614
prev: result,
615615
key: current.key,
616616
index: current.index,
617+
value: current.value,
617618
}
618619
current = current.Parent()
619620
}

libs/structs/structpath/path_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,38 @@ func TestPrefixAndSkipPrefix(t *testing.T) {
551551
prefix: "",
552552
skipPrefix: "resources.jobs.my_job.tasks[0].name",
553553
},
554+
// Regression test for SkipPrefix bug: value field was missing in KeyValue nodes
555+
// Test all possible n values for completeness
556+
{
557+
input: "resources.jobs[task_key='my_task'].notebook_task",
558+
n: 0,
559+
prefix: "",
560+
skipPrefix: "resources.jobs[task_key='my_task'].notebook_task",
561+
},
562+
{
563+
input: "resources.jobs[task_key='my_task'].notebook_task",
564+
n: 1,
565+
prefix: "resources",
566+
skipPrefix: "jobs[task_key='my_task'].notebook_task",
567+
},
568+
{
569+
input: "resources.jobs[task_key='my_task'].notebook_task",
570+
n: 2,
571+
prefix: "resources.jobs",
572+
skipPrefix: "[task_key='my_task'].notebook_task",
573+
},
574+
{
575+
input: "resources.jobs[task_key='my_task'].notebook_task",
576+
n: 3,
577+
prefix: "resources.jobs[task_key='my_task']",
578+
skipPrefix: "notebook_task",
579+
},
580+
{
581+
input: "resources.jobs[task_key='my_task'].notebook_task",
582+
n: 4,
583+
prefix: "resources.jobs[task_key='my_task'].notebook_task",
584+
skipPrefix: "",
585+
},
554586
}
555587

556588
for _, tt := range tests {

0 commit comments

Comments
 (0)