mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Only validate segmentation values for Mixpanel (#16889)
GitOrigin-RevId: 3cb9de7648d1ba1f9faa8720eb57370e224c0c8c
This commit is contained in:
parent
956dd7659b
commit
5650b38069
2 changed files with 9 additions and 18 deletions
|
@ -275,25 +275,16 @@ function _isAttributeValueValid(attributeValue) {
|
|||
return _isAttributeValid(attributeValue) || attributeValue instanceof Date
|
||||
}
|
||||
|
||||
function _isSegmentationValueValid(attributeValue) {
|
||||
// spaces and %-escaped values are allowed for segmentation values
|
||||
return !attributeValue || /^[a-zA-Z0-9-_.:;,/ %]+$/.test(attributeValue)
|
||||
}
|
||||
|
||||
function _isSegmentationValid(segmentation) {
|
||||
if (!segmentation) {
|
||||
return true
|
||||
if (segmentation) {
|
||||
for (const key of Object.keys(segmentation)) {
|
||||
if (!_isAttributeValid(key)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const hasAnyInvalidKey = [...Object.keys(segmentation)].some(
|
||||
key => !_isAttributeValid(key)
|
||||
)
|
||||
|
||||
const hasAnyInvalidValue = [...Object.values(segmentation)].some(
|
||||
value => !_isSegmentationValueValid(value)
|
||||
)
|
||||
|
||||
return !hasAnyInvalidKey && !hasAnyInvalidValue
|
||||
return true
|
||||
}
|
||||
|
||||
function getIdsFromSession(session) {
|
||||
|
|
|
@ -112,7 +112,7 @@ describe('AnalyticsManager', function () {
|
|||
this.fakeUserId,
|
||||
'789ghi',
|
||||
'fr',
|
||||
{ key: '<alert>' }
|
||||
{ '<alert>': 'foo' }
|
||||
)
|
||||
sinon.assert.called(this.logger.info)
|
||||
sinon.assert.notCalled(this.analyticsEditingSessionQueue.add)
|
||||
|
@ -131,7 +131,7 @@ describe('AnalyticsManager', function () {
|
|||
await this.AnalyticsManager.recordEventForUser(
|
||||
this.fakeUserId,
|
||||
'an_event',
|
||||
{ not_a: 'Valid Segmentation!' }
|
||||
{ 'not_a!': 'Valid Segmentation' }
|
||||
)
|
||||
sinon.assert.called(this.logger.info)
|
||||
sinon.assert.notCalled(this.analyticsEventsQueue.add)
|
||||
|
|
Loading…
Reference in a new issue