Skip to content

Commit

Permalink
Replace erroneous string sorting with numeric sorting (#1463)
Browse files Browse the repository at this point in the history
Without this, the check for trigger_data_matching with modulus
erroneously fails when a multi-digit number is used as trigger data.
  • Loading branch information
apasel422 authored Nov 12, 2024
1 parent f19c929 commit 470cc94
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 15 additions & 2 deletions ts/src/header-validator/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2639,18 +2639,31 @@ 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,
},
{
name: 'trigger-data-matching-modulus-valid-within',
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,
},
},
},

{
Expand Down
6 changes: 5 additions & 1 deletion ts/src/header-validator/validate-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(
Expand Down

0 comments on commit 470cc94

Please sign in to comment.