Skip to content

Commit 1ec7331

Browse files
committed
Fixed a deep copy bug in MemoryStorage class. I now use JSON.stringify() & JSON.parse() to ensure a deep copy.
1 parent 2383e5d commit 1ec7331

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Node/src/storage/Storage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ export interface IStorage {
3939
}
4040

4141
export class MemoryStorage implements IStorage {
42-
private store: { [id: string]: any; } = {};
42+
private store: { [id: string]: string; } = {};
4343

4444
public get(id: string, callback: (err: Error, data: any) => void): void {
4545
if (this.store.hasOwnProperty(id)) {
46-
callback(null, utils.clone(this.store[id]));
46+
callback(null, JSON.parse(this.store[id]));
4747
} else {
4848
callback(null, null);
4949
}
5050
}
5151

5252
public save(id: string, data: any, callback?: (err: Error) => void): void {
53-
this.store[id] = utils.clone(data || {});
53+
this.store[id] = JSON.stringify(data || {});
5454
if (callback) {
5555
callback(null);
5656
}

0 commit comments

Comments
 (0)