Skip to content

Commit

Permalink
fix: createEventsToDropByToken should handle tokens with multiple s…
Browse files Browse the repository at this point in the history
…eparators (#20392)
  • Loading branch information
tkaemming authored Feb 17, 2024
1 parent 6c32341 commit 644cc6f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion plugin-server/src/utils/db/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export function createEventsToDropByToken(eventsToDropByTokenStr?: string): Map<
const eventsToDropByToken: Map<string, string[]> = new Map()
if (eventsToDropByTokenStr) {
eventsToDropByTokenStr.split(',').forEach((pair) => {
const [token, distinctID] = pair.split(':')
const separatorIndex = pair.indexOf(':')
const token = pair.substring(0, separatorIndex)
const distinctID = pair.substring(separatorIndex + 1)
eventsToDropByToken.set(token, [...(eventsToDropByToken.get(token) || []), distinctID])
})
}
Expand Down
10 changes: 10 additions & 0 deletions plugin-server/tests/utils/db/hub.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createEventsToDropByToken } from '../../../src/utils/db/hub'

describe('createEventsToDropByToken', () => {
it('should split tokens on comma', () => {
expect(createEventsToDropByToken('x:y,x:z')).toEqual(new Map([['x', ['y', 'z']]]))
})
it('handles events with duplicate separators', () => {
expect(createEventsToDropByToken('x:a,x:y:z,x:b')).toEqual(new Map([['x', ['a', 'y:z', 'b']]]))
})
})

0 comments on commit 644cc6f

Please sign in to comment.