mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Avoid aliasing in fsnode by forcing copies for file contents and add a test
This commit is contained in:
@@ -123,11 +123,11 @@ func (n *fsNode) addFile(name string, c []byte) (result *fsNode, err error) {
|
||||
if result.offset != nil {
|
||||
return nil, fmt.Errorf("cannot add already opened file '%s'", n.Path())
|
||||
}
|
||||
result.content = c
|
||||
result.content = append(result.content[:0], c...)
|
||||
return result, nil
|
||||
}
|
||||
result = &fsNode{
|
||||
content: c,
|
||||
content: append([]byte(nil), c...),
|
||||
parent: parent,
|
||||
}
|
||||
parent.dir[fileName] = result
|
||||
|
||||
@@ -157,9 +157,13 @@ func runBasicOperations(
|
||||
if string(stuff) != both {
|
||||
t.Fatalf("%s; unexpected content '%s', expected '%s'", c.what, stuff, both)
|
||||
}
|
||||
if err := fSys.WriteFile(c.path, []byte(shortContent)); err != nil {
|
||||
|
||||
content := []byte(shortContent)
|
||||
if err := fSys.WriteFile(c.path, content); err != nil {
|
||||
t.Fatalf("%s; unexpected error: %v", c.what, err)
|
||||
}
|
||||
// This ensures that modifying the original slice does not change the contents of the file.
|
||||
content[0] = '@'
|
||||
stuff, err = fSys.ReadFile(c.path)
|
||||
if err != nil {
|
||||
t.Fatalf("%s; unexpected error: %v", c.what, err)
|
||||
|
||||
Reference in New Issue
Block a user