Skip to content

Commit

Permalink
Fix warning in DynamicMap (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
JairusSW authored Jan 8, 2025
1 parent 387d19e commit c1cb469
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## UNRELEASED

- fix: resolve warning in `deserializeRawMap` [#692](https://github.com/hypermodeinc/modus/pull/692)

## 2025-01-07 - CLI 0.16.5

- fix: handle space in user profile path [#696](https://github.com/hypermodeinc/modus/pull/696)
Expand Down
9 changes: 9 additions & 0 deletions sdk/assemblyscript/src/assembly/__tests__/dynamicmap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ class Obj {
foo: string = "";
}

it("should handle nulls correctly", () => {
const m1 = JSON.parse<DynamicMap>('{"a":null}');
const m2 = new DynamicMap();
m2.set("a", null);

expect(JSON.stringify(m1)).toBe('{"a":null}');
expect(JSON.stringify(m2)).toBe('{"a":null}');
});

it("should parse complex values", () => {
const input =
'{"a":{"b":{"c":[{"d":"random value 1"},{"e":["value 2","value 3"]}],"f":{"g":{"h":[1,2,3],"i":{"j":"nested value"}}}},"k":"simple value"},"l":[{"m":"another value","n":{"o":"deep nested","p":[{"q":"even deeper"},"final value"]}}],"r":null}';
Expand Down
2 changes: 1 addition & 1 deletion sdk/assemblyscript/src/assembly/dynamicmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class DynamicMap {
}

public set<T>(key: string, value: T): void {
if (value == null) {
if (isInteger<T>() && nameof<T>() == "usize" && value == 0) {
this.data.set(key, "null");
} else {
this.data.set(key, JSON.stringify(value));
Expand Down

0 comments on commit c1cb469

Please sign in to comment.