Skip to content

Commit 964746f

Browse files
committed
BUGFIX: WithProperty and WithIndex should copy the underying array to prevent changing sibling's values
Signed-off-by: Tim Ramlot <[email protected]>
1 parent a75f4cc commit 964746f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

paths/path.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,15 @@ func Parse(pathString string) (Path, error) {
108108
}
109109

110110
func (p Path) WithProperty(part string) Path {
111-
return append(p, mapPathComponent(part))
111+
nePath := append(Path{}, p...)
112+
nePath = append(nePath, mapPathComponent(part))
113+
return nePath
112114
}
113115

114116
func (p Path) WithIndex(idx int) Path {
115-
return append(p, arrayPathComponent(idx))
117+
nePath := append(Path{}, p...)
118+
nePath = append(nePath, arrayPathComponent(idx))
119+
return nePath
116120
}
117121

118122
func (p Path) Property() pathComponent {

0 commit comments

Comments
 (0)