Skip to content

Commit

Permalink
ensure that null value is transformed to as string
Browse files Browse the repository at this point in the history
  • Loading branch information
codecapitano committed Feb 7, 2025
1 parent 9fac187 commit 696dad2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/utils/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('json', () => {
});

it('stringifyObjectValues function stringifies object values', () => {
const obj = { a: 1, b: { c: 2 }, d: 'foo', e: true, f: [true, 'a', 1] };
const obj = { a: 1, b: { c: 2 }, d: 'foo', e: true, f: [true, 'a', 1], g: null };

const objectWithStringifiedValues = stringifyObjectValues(obj);
expect(objectWithStringifiedValues).toStrictEqual({
Expand All @@ -27,6 +27,7 @@ describe('json', () => {
d: 'foo',
e: 'true',
f: '[true,\"a\",1]',
g: 'null',
});

Object.values(objectWithStringifiedValues).forEach((key) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isObject } from './is';
export function getCircularDependencyReplacer() {
const valueSeen = new WeakSet();
return function (_key: string | Symbol, value: unknown) {
if (typeof value === 'object' && value !== null) {
if (isObject(value) && value !== null) {
if (valueSeen.has(value)) {
return null;
}
Expand All @@ -27,7 +27,7 @@ export function stringifyObjectValues(obj: Record<string, unknown> = {}) {
const o: Record<string, string> = {};

for (const [key, value] of Object.entries(obj)) {
o[key] = isObject(value) ? stringifyExternalJson(value) : String(value);
o[key] = isObject(value) && value !== null ? stringifyExternalJson(value) : String(value);
}

return o;
Expand Down

0 comments on commit 696dad2

Please sign in to comment.