Skip to content

Commit

Permalink
Merge pull request #6 from duckduckgo/sam/validator-fixes
Browse files Browse the repository at this point in the history
Live pixel validation: remove cache-buster before parameter validation
  • Loading branch information
sammacbeth authored Jan 13, 2025
2 parents fe00f16 + 9a67ed0 commit de3f8b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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

0 comments on commit de3f8b5

Please sign in to comment.