From 34c446909e9a2f3c0bb3809d19d269a311fb31f1 Mon Sep 17 00:00:00 2001 From: Esther Lozano Date: Wed, 26 Feb 2020 14:50:41 +0100 Subject: [PATCH] Trim fields when normalizing --- lib/api/middlewares/pubsub-metrics.js | 2 +- test/integration/pubsub-metrics-test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/api/middlewares/pubsub-metrics.js b/lib/api/middlewares/pubsub-metrics.js index 35707f4a..7ccdb39c 100644 --- a/lib/api/middlewares/pubsub-metrics.js +++ b/lib/api/middlewares/pubsub-metrics.js @@ -45,7 +45,7 @@ function getEventData (req, res) { } function normalizedField (field) { - return field.toString().substr(0, MAX_LENGTH); + return field.toString().trim().substr(0, MAX_LENGTH); } module.exports = pubSubMetrics; diff --git a/test/integration/pubsub-metrics-test.js b/test/integration/pubsub-metrics-test.js index fb0855ab..6bb8110d 100644 --- a/test/integration/pubsub-metrics-test.js +++ b/test/integration/pubsub-metrics-test.js @@ -12,7 +12,7 @@ const metricsHeaders = { 'Carto-Event-Group-Id': '1' }; -const tooLongField = 'If you are sending a text this long in a header you kind of deserve the worst, honestly. I mean ' + +const tooLongField = ' If you are sending a text this long in a header you kind of deserve the worst, honestly. I mean ' + 'this is not a header, it is almost a novel, and you do not see any Novel cookie here, right?'; const badHeaders = { @@ -119,7 +119,7 @@ describe('pubsub metrics middleware', function () { global.environment.pubSubMetrics.enabled = true; const eventAttributes = buildEventAttributes(200); const maxLength = 100; - const eventName = tooLongField.substr(0, maxLength); + const eventName = tooLongField.trim().substr(0, maxLength); testClient = new TestClient(mapConfig, 1234, badHeaders);