Skip to content

Commit bf15d7e

Browse files
committed
Properly prevent NaN session index parameter 'vid' (fix #1204)
#1207
1 parent c2d24c3 commit bf15d7e

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/node-tracker",
5+
"comment": "Properly prevent NaN session index parameter 'vid' (fix #1204)",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/node-tracker"
10+
}

trackers/node-tracker/src/tracker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function tracker(
9494
payload.add('duid', domainUserId);
9595
payload.add('nuid', networkUserId);
9696
payload.add('sid', sessionId);
97-
payload.add('vid', Number(sessionIndex));
97+
payload.add('vid', sessionIndex && Number(sessionIndex));
9898
};
9999

100100
/**

trackers/node-tracker/test/tracker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ function checkPayload(payloadDict: Payload, expected: Payload, t: ExecutionConte
9595
t.deepEqual(payloadDict['co'], completedContext, 'a custom context should be attached');
9696
t.truthy(payloadDict['dtm'], 'a timestamp should be attached');
9797
t.truthy(payloadDict['eid'], 'a UUID should be attached');
98+
t.falsy(typeof payloadDict['vid'] === 'string' && payloadDict['vid'] === 'NaN', 'Session index should not be NaN');
9899
}
99100

100101
test.before(() => {

0 commit comments

Comments
 (0)