BUGFIX: Properly deep copy array data for coding contracts (#1064)

This commit is contained in:
LJ
2024-01-31 17:43:04 -07:00
committed by GitHub
parent 5277db2c65
commit 011d5e8fd6
2 changed files with 4 additions and 13 deletions
+2 -11
View File
@@ -67,17 +67,8 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
const contract = getCodingContract(ctx, hostname, filename);
const data = contract.getData();
if (Array.isArray(data)) {
// For two dimensional arrays, we have to copy the internal arrays using
// slice() as well. As of right now, no contract has arrays that have
// more than two dimensions
const copy = data.slice();
for (let i = 0; i < copy.length; ++i) {
if (data[i].constructor === Array) {
copy[i] = data[i].slice();
}
}
return copy;
// For multi-dimensional arrays, we have to copy the internal arrays as well
return JSON.parse(JSON.stringify(data));
} else return data;
},
getDescription: (ctx) => (_filename, _hostname?) => {