Skip to content

Commit

Permalink
fix(UtilService): Handle undefined param in makeCopyOfJSONObject() (#672
Browse files Browse the repository at this point in the history
)
  • Loading branch information
hirokiterashima authored Jul 15, 2022
1 parent 19474e3 commit 53c65e2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/app/services/utilService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ function makeCopyOfJSONObjectTests() {
it('should return null for null input', () => {
expect(service.makeCopyOfJSONObject(null)).toEqual(null);
});

it('should return undefined for undefined input', () => {
expect(service.makeCopyOfJSONObject(undefined)).toEqual(undefined);
});
});
}

Expand Down
8 changes: 6 additions & 2 deletions src/assets/wise5/services/utilService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ export class UtilService {
return str;
}

makeCopyOfJSONObject(jsonObject): any {
return JSON.parse(JSON.stringify(jsonObject));
makeCopyOfJSONObject(jsonObject: any): any {
return this.isUndefined(jsonObject) ? undefined : JSON.parse(JSON.stringify(jsonObject));
}

private isUndefined(value: any): boolean {
return typeof value === 'undefined';
}

getImageObjectFromBase64String(img_b64) {
Expand Down
6 changes: 3 additions & 3 deletions src/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -16315,21 +16315,21 @@ If this problem continues, let your teacher know and move on to the next activit
<source>Saved <x id="saveTime" equiv-text="saveTimeText"/></source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/utilService.ts</context>
<context context-type="linenumber">787</context>
<context context-type="linenumber">791</context>
</context-group>
</trans-unit>
<trans-unit id="5275881069346355759" datatype="html">
<source>Auto Saved <x id="saveTime" equiv-text="saveTimeText"/></source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/utilService.ts</context>
<context context-type="linenumber">792</context>
<context context-type="linenumber">796</context>
</context-group>
</trans-unit>
<trans-unit id="2692433425768915750" datatype="html">
<source>Submitted <x id="saveTime" equiv-text="saveTimeText"/></source>
<context-group purpose="location">
<context context-type="sourcefile">src/assets/wise5/services/utilService.ts</context>
<context context-type="linenumber">797</context>
<context context-type="linenumber">801</context>
</context-group>
</trans-unit>
<trans-unit id="846fecebb7756c6127955bc2c08d2111dce64c3c" datatype="html">
Expand Down

0 comments on commit 53c65e2

Please sign in to comment.