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

[ParrableIdSystem] Accept lowercase timezone names in timezone filter #6282

Merged
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
13 changes: 10 additions & 3 deletions modules/parrableIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import * as utils from '../src/utils.js'
import find from 'core-js-pure/features/array/find.js';
import { ajax } from '../src/ajax.js';
import { submodule } from '../src/hook.js';
import { getRefererInfo } from '../src/refererDetection.js';
Expand Down Expand Up @@ -137,12 +138,18 @@ function shouldFilterImpression(configParams, parrableId) {
const offset = (new Date()).getTimezoneOffset() / 60;
const zone = Intl.DateTimeFormat().resolvedOptions().timeZone;

function isZoneListed(list, zone) {
// IE does not provide a timeZone in IANA format so zone will be empty
const zoneLowercase = zone && zone.toLowerCase();
return !!(list && zone && find(list, zn => zn.toLowerCase() === zoneLowercase));
}

function isAllowed() {
if (utils.isEmpty(config.allowedZones) &&
utils.isEmpty(config.allowedOffsets)) {
return true;
}
if (utils.contains(config.allowedZones, zone)) {
if (isZoneListed(config.allowedZones, zone)) {
return true;
}
if (utils.contains(config.allowedOffsets, offset)) {
Expand All @@ -156,7 +163,7 @@ function shouldFilterImpression(configParams, parrableId) {
utils.isEmpty(config.blockedOffsets)) {
return false;
}
if (utils.contains(config.blockedZones, zone)) {
if (isZoneListed(config.blockedZones, zone)) {
return true;
}
if (utils.contains(config.blockedOffsets, offset)) {
Expand All @@ -165,7 +172,7 @@ function shouldFilterImpression(configParams, parrableId) {
return false;
}

return !isAllowed() || isBlocked();
return isBlocked() || !isAllowed();
}

function fetchId(configParams, gdprConsentData) {
Expand Down
28 changes: 28 additions & 0 deletions test/spec/modules/parrableIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,20 @@ describe('Parrable ID System', function() {
expect(resolvedOptions.called).to.equal(true);
});

it('permits an impression from a lower cased allowed timezone', function() {
const allowedZone = 'America/New_York';
const resolvedOptions = sinon.stub().returns({ timeZone: allowedZone });
Intl.DateTimeFormat.returns({ resolvedOptions });

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
timezoneFilter: {
allowedZones: [ allowedZone.toLowerCase() ]
}
} })).to.have.property('callback');
expect(resolvedOptions.called).to.equal(true);
});

it('permits an impression from a timezone that is not blocked', function() {
const blockedZone = 'America/New_York';
const resolvedOptions = sinon.stub().returns({ timeZone: 'Iceland' });
Expand Down Expand Up @@ -333,6 +347,20 @@ describe('Parrable ID System', function() {
expect(resolvedOptions.called).to.equal(true);
});

it('does not permit an impression from a lower cased blocked timezone', function() {
const blockedZone = 'America/New_York';
const resolvedOptions = sinon.stub().returns({ timeZone: blockedZone });
Intl.DateTimeFormat.returns({ resolvedOptions });

expect(parrableIdSubmodule.getId({ params: {
partner: 'prebid-test',
timezoneFilter: {
blockedZones: [ blockedZone.toLowerCase() ]
}
} })).to.equal(null);
expect(resolvedOptions.called).to.equal(true);
});

it('does not permit an impression from a blocked timezone even when also allowed', function() {
const timezone = 'America/New_York';
const resolvedOptions = sinon.stub().returns({ timeZone: timezone });
Expand Down