From d03e9d1ace485ca1b8bc081104506ecb85d0b78e Mon Sep 17 00:00:00 2001 From: Sam Macbeth Date: Fri, 10 Jan 2025 14:40:12 +0100 Subject: [PATCH 1/2] Fix running validate_live_pixel via npx --- bin/validate_live_pixel.mjs | 2 ++ 1 file changed, 2 insertions(+) mode change 100644 => 100755 bin/validate_live_pixel.mjs diff --git a/bin/validate_live_pixel.mjs b/bin/validate_live_pixel.mjs old mode 100644 new mode 100755 index dca8c41..16daa8d --- a/bin/validate_live_pixel.mjs +++ b/bin/validate_live_pixel.mjs @@ -1,3 +1,5 @@ +#!/usr/bin/env node + import fs from 'fs'; import JSON5 from 'json5'; From 9a67ed03f58ce81febc1b3a02594429585443c79 Mon Sep 17 00:00:00 2001 From: Sam Macbeth Date: Fri, 10 Jan 2025 15:06:52 +0100 Subject: [PATCH 2/2] Remove cache busting prefix from pixel live URL when validating --- src/params_validator.mjs | 3 ++- tests/live_pixel_validation_test.mjs | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/params_validator.mjs b/src/params_validator.mjs index 829acd4..0f241e5 100644 --- a/src/params_validator.mjs +++ b/src/params_validator.mjs @@ -140,7 +140,8 @@ export class ParamsValidator { const urlSplit = url.split('/')[2].split('?'); const livePixelName = urlSplit[0].replaceAll('_', '.'); - const livePixelRequestParams = urlSplit[1]; + // grab pixel parameters with any preciding cache buster removed + const livePixelRequestParams = /^([0-9]+&)?(.*)$/.exec(urlSplit[1] || '')[2]; // 1) Validate pixel name if it's parameterized if (livePixelName.length > prefix.length) { diff --git a/tests/live_pixel_validation_test.mjs b/tests/live_pixel_validation_test.mjs index 3cf5548..9c34414 100644 --- a/tests/live_pixel_validation_test.mjs +++ b/tests/live_pixel_validation_test.mjs @@ -46,6 +46,13 @@ describe('No common params nor suffixes', () => { const expectedErrors = ["must NOT have additional properties. Found extra property 'param2'"]; expect(errors).to.have.members(expectedErrors); }); + + it('ignores cache buster', () => { + const prefix = 'simplePixel'; + const url = `/t/${prefix}?12345¶m1=true`; + const errors = paramsValidator.validateLivePixels(pixelDefs[prefix], prefix, url); + expect(errors).to.be.empty; + }); }); describe('Common params', () => {