Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live pixel validation: remove cache-buster before parameter validation #6

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/validate_live_pixel.mjs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

import fs from 'fs';
import JSON5 from 'json5';

Expand Down
3 changes: 2 additions & 1 deletion src/params_validator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions tests/live_pixel_validation_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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&param1=true`;
const errors = paramsValidator.validateLivePixels(pixelDefs[prefix], prefix, url);
expect(errors).to.be.empty;
});
});

describe('Common params', () => {
Expand Down
Loading