From daa9302fd3ac743cb55ef3cd20364c76b85488c3 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 18 Jul 2022 09:03:59 +0100 Subject: [PATCH] Merge pull request #8895 from overleaf/jpa-allow-empty-segmentation-val [web] allow empty event segmentation values again GitOrigin-RevId: a02fd5085697bf7e2f2d4a5c2dc93dfebcd6e140 --- .../Features/Analytics/AnalyticsManager.js | 2 +- .../src/Analytics/AnalyticsManagerTests.js | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/services/web/app/src/Features/Analytics/AnalyticsManager.js b/services/web/app/src/Features/Analytics/AnalyticsManager.js index 22c068b115..7d8cce9f12 100644 --- a/services/web/app/src/Features/Analytics/AnalyticsManager.js +++ b/services/web/app/src/Features/Analytics/AnalyticsManager.js @@ -243,7 +243,7 @@ function _checkPropertyValue(propertyValue) { } function _isAttributeValid(attribute) { - return attribute && /^[a-zA-Z0-9-_.:;,/]+$/.test(attribute) + return !attribute || /^[a-zA-Z0-9-_.:;,/]+$/.test(attribute) } function _isSegmentationValid(segmentation) { diff --git a/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js b/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js index 796c00516a..72d3ff7544 100644 --- a/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js +++ b/services/web/test/unit/src/Analytics/AnalyticsManagerTests.js @@ -209,6 +209,35 @@ describe('AnalyticsManager', function () { } ) }) + + it('empty field in event segmentation', async function () { + const timings = null + await this.AnalyticsManager.recordEventForUser( + this.fakeUserId, + 'an_event', + { compileTime: timings?.compileE2E } + ) + sinon.assert.calledWithMatch(this.analyticsEventsQueue.add, 'event', { + analyticsId: this.analyticsId, + event: 'an_event', + segmentation: { compileTime: undefined }, + isLoggedIn: true, + }) + }) + + it('boolean field in event segmentation', async function () { + await this.AnalyticsManager.recordEventForUser( + this.fakeUserId, + 'an_event', + { isAutoCompile: false } + ) + sinon.assert.calledWithMatch(this.analyticsEventsQueue.add, 'event', { + analyticsId: this.analyticsId, + event: 'an_event', + segmentation: { isAutoCompile: false }, + isLoggedIn: true, + }) + }) }) describe('AnalyticsIdMiddleware', function () {