From b0434e20646a42447dc70981be2755e2d18da339 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Fri, 16 Aug 2024 16:05:04 +0200 Subject: [PATCH 1/6] fix(normalize): Treat Infinity as NaN both are non-serializable numbers --- packages/utils/src/normalize.ts | 10 +++++++++- packages/utils/test/normalize.test.ts | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/utils/src/normalize.ts b/packages/utils/src/normalize.ts index d86af9561c89..82573767547c 100644 --- a/packages/utils/src/normalize.ts +++ b/packages/utils/src/normalize.ts @@ -81,7 +81,7 @@ 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)) + (['number', 'boolean', 'string'].includes(typeof value) && Number.isFinite(value)) ) { return value as Primitive; } @@ -224,6 +224,14 @@ function stringifyValue( return '[NaN]'; } + if (typeof value === 'number' && value === Infinity) { + return '[Infinity]'; + } + + if (typeof value === 'number' && value === -Infinity) { + return '[-Infinity]'; + } + if (typeof value === 'function') { return `[Function: ${getFunctionName(value)}]`; } 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]'); }); From ac9939e3202bb8412a510a41a28d77457caa37f5 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Tue, 27 Aug 2024 14:21:42 +0200 Subject: [PATCH 2/6] fix infinity normalization --- packages/utils/src/normalize.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/utils/src/normalize.ts b/packages/utils/src/normalize.ts index 82573767547c..d1d6fd08242c 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.isFinite(value)) + (['boolean', 'string'].includes(typeof value) || + (typeof value === 'number' && Number.isFinite(value))) ) { return value as Primitive; } From 39c1249bf29537b455742c86402c88b34f02f5d9 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Tue, 27 Aug 2024 14:29:37 +0200 Subject: [PATCH 3/6] use one if for both positive and negative --- packages/utils/src/normalize.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/utils/src/normalize.ts b/packages/utils/src/normalize.ts index d1d6fd08242c..9518f6dd0924 100644 --- a/packages/utils/src/normalize.ts +++ b/packages/utils/src/normalize.ts @@ -225,12 +225,8 @@ function stringifyValue( return '[NaN]'; } - if (typeof value === 'number' && value === Infinity) { - return '[Infinity]'; - } - - if (typeof value === 'number' && value === -Infinity) { - return '[-Infinity]'; + if (typeof value === 'number' && !Number.isFinite(value)) { + return `[${value}]`; } if (typeof value === 'function') { From 61b15544dea42fd939a00d3e2f52b733caedba9f Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Wed, 28 Aug 2024 10:25:55 +0200 Subject: [PATCH 4/6] remove explicit NaN check as NaN is not finite --- packages/utils/src/normalize.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/utils/src/normalize.ts b/packages/utils/src/normalize.ts index 9518f6dd0924..9217cd8bb5f3 100644 --- a/packages/utils/src/normalize.ts +++ b/packages/utils/src/normalize.ts @@ -221,10 +221,6 @@ function stringifyValue( return '[SyntheticEvent]'; } - if (typeof value === 'number' && value !== value) { - return '[NaN]'; - } - if (typeof value === 'number' && !Number.isFinite(value)) { return `[${value}]`; } From f664a5f43cb372800d1a3e96c0544d8b8d89dae9 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Tue, 10 Sep 2024 11:05:10 +0200 Subject: [PATCH 5/6] fix ee2e tests --- .../suites/public-api/setExtras/consecutive_calls/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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..95e4660e3360 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,5 @@ sentryTest('should set extras from multiple consecutive calls', async ({ getLoca const eventData = await getFirstSentryEnvelopeRequest(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] } }); }); From d265d927ee87d5c50fdebc62da926ddea3c95912 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Tue, 10 Sep 2024 13:39:52 +0200 Subject: [PATCH 6/6] fix lint --- .../suites/public-api/setExtras/consecutive_calls/test.ts | 7 ++++++- packages/utils/src/normalize.ts | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) 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 95e4660e3360..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(page, url); expect(eventData.message).toBe('consecutive_calls'); - expect(eventData.extra).toMatchObject({ extra: [], Infinity: 2, null: '[Infinity]', 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 9217cd8bb5f3..18b41f1c9357 100644 --- a/packages/utils/src/normalize.ts +++ b/packages/utils/src/normalize.ts @@ -81,8 +81,8 @@ function visit( // Get the simple cases out of the way first if ( value == null || // this matches null and undefined -> eqeq not eqeqeq - (['boolean', 'string'].includes(typeof value) || - (typeof value === 'number' && Number.isFinite(value))) + ['boolean', 'string'].includes(typeof value) || + (typeof value === 'number' && Number.isFinite(value)) ) { return value as Primitive; }