diff --git a/dev-packages/browser-integration-tests/suites/public-api/setExtras/consecutive_calls/test.ts b/dev-packages/browser-integration-tests/suites/public-api/setExtras/consecutive_calls/test.ts index 9caae5b0bc7c..555686058366 100644 --- a/dev-packages/browser-integration-tests/suites/public-api/setExtras/consecutive_calls/test.ts +++ b/dev-packages/browser-integration-tests/suites/public-api/setExtras/consecutive_calls/test.ts @@ -10,5 +10,10 @@ sentryTest('should set extras from multiple consecutive calls', async ({ getLoca const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); expect(eventData.message).toBe('consecutive_calls'); - expect(eventData.extra).toMatchObject({ extra: [], Infinity: 2, null: null, obj: { foo: ['bar', 'baz', 1] } }); + expect(eventData.extra).toMatchObject({ + extra: [], + Infinity: 2, + null: '[Infinity]', + obj: { foo: ['bar', 'baz', 1] }, + }); }); diff --git a/packages/utils/src/normalize.ts b/packages/utils/src/normalize.ts index d86af9561c89..18b41f1c9357 100644 --- a/packages/utils/src/normalize.ts +++ b/packages/utils/src/normalize.ts @@ -81,7 +81,8 @@ function visit( // Get the simple cases out of the way first if ( value == null || // this matches null and undefined -> eqeq not eqeqeq - (['number', 'boolean', 'string'].includes(typeof value) && !Number.isNaN(value)) + ['boolean', 'string'].includes(typeof value) || + (typeof value === 'number' && Number.isFinite(value)) ) { return value as Primitive; } @@ -220,8 +221,8 @@ function stringifyValue( return '[SyntheticEvent]'; } - if (typeof value === 'number' && value !== value) { - return '[NaN]'; + if (typeof value === 'number' && !Number.isFinite(value)) { + return `[${value}]`; } if (typeof value === 'function') { diff --git a/packages/utils/test/normalize.test.ts b/packages/utils/test/normalize.test.ts index 5a2414d52e43..d8a8a1329352 100644 --- a/packages/utils/test/normalize.test.ts +++ b/packages/utils/test/normalize.test.ts @@ -403,6 +403,8 @@ describe('normalize()', () => { describe('changes unserializeable/global values/classes to their respective string representations', () => { test('primitive values', () => { expect(normalize(NaN)).toEqual('[NaN]'); + expect(normalize(Infinity)).toEqual('[Infinity]'); + expect(normalize(-Infinity)).toEqual('[-Infinity]'); expect(normalize(Symbol('dogs'))).toEqual('[Symbol(dogs)]'); expect(normalize(BigInt(1121201212312012))).toEqual('[BigInt: 1121201212312012]'); });