From 470cc949fa1a0394fda417c069cf38e2634071e2 Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Tue, 12 Nov 2024 13:19:11 -0500 Subject: [PATCH] Replace erroneous string sorting with numeric sorting (#1463) Without this, the check for trigger_data_matching with modulus erroneously fails when a multi-digit number is used as trigger data. --- ts/src/header-validator/source.test.ts | 17 +++++++++++++++-- ts/src/header-validator/validate-source.ts | 6 +++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ts/src/header-validator/source.test.ts b/ts/src/header-validator/source.test.ts index d8c7d1e008..8c081c0ccb 100644 --- a/ts/src/header-validator/source.test.ts +++ b/ts/src/header-validator/source.test.ts @@ -2639,9 +2639,16 @@ const testCases: TestCase[] = [ "trigger_specs": [ {"trigger_data": [1, 0]}, {"trigger_data": [3]}, - {"trigger_data": [2]} + {"trigger_data": [2]}, + {"trigger_data": [4, 5, 6, 7, 8, 9, 10]} ] }`, + vsv: { + maxEventLevelChannelCapacityPerSource: { + [SourceType.event]: Infinity, + [SourceType.navigation]: Infinity, + }, + }, parseFullFlex: true, }, { @@ -2649,8 +2656,14 @@ const testCases: TestCase[] = [ input: `{ "destination": "https://a.test", "trigger_data_matching": "modulus", - "trigger_data": [1, 0, 2, 3] + "trigger_data": [1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10] }`, + vsv: { + maxEventLevelChannelCapacityPerSource: { + [SourceType.event]: Infinity, + [SourceType.navigation]: Infinity, + }, + }, }, { diff --git a/ts/src/header-validator/validate-source.ts b/ts/src/header-validator/validate-source.ts index 1b17599555..1d1dd86ed2 100644 --- a/ts/src/header-validator/validate-source.ts +++ b/ts/src/header-validator/validate-source.ts @@ -625,6 +625,10 @@ function defaultTriggerSpecs( ) } +function compareNumbers(a: number, b: number): number { + return a - b +} + function isTriggerDataMatchingValidForSpecs(s: Source, ctx: Context): boolean { return ctx.scope('trigger_data_matching', () => { if (s.triggerDataMatching !== TriggerDataMatching.modulus) { @@ -633,7 +637,7 @@ function isTriggerDataMatchingValidForSpecs(s: Source, ctx: Context): boolean { const triggerData: number[] = s.triggerSpecs .flatMap((spec) => Array.from(spec.triggerData)) - .sort() + .sort(compareNumbers) if (triggerData.some((triggerDatum, i) => triggerDatum !== i)) { ctx.error(