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

Core PBjs : add check for empty mediaquery declaration in sizeConfig object #6487

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 8 additions & 13 deletions src/sizeMapping.js
Original file line number Diff line number Diff line change
@@ -121,22 +121,17 @@ function evaluateSizeConfig(configs) {
return configs.reduce((results, config) => {
if (
typeof config === 'object' &&
typeof config.mediaQuery === 'string'
typeof config.mediaQuery === 'string' &&
config.mediaQuery.length > 0
) {
let ruleMatch = false;

// TODO: (Prebid - 4.0) Remove empty mediaQuery string check. Disallow empty mediaQuery in sizeConfig.
// Refer: https://github.com/prebid/Prebid.js/pull/4691, https://github.com/prebid/Prebid.js/issues/4810 for more details.
if (config.mediaQuery === '') {
ruleMatch = true;
} else {
try {
ruleMatch = getWindowTop().matchMedia(config.mediaQuery).matches;
} catch (e) {
logWarn('Unfriendly iFrame blocks sizeConfig from being correctly evaluated');

ruleMatch = matchMedia(config.mediaQuery).matches;
}
try {
ruleMatch = getWindowTop().matchMedia(config.mediaQuery).matches;
} catch (e) {
logWarn('Unfriendly iFrame blocks sizeConfig from being correctly evaluated');

ruleMatch = matchMedia(config.mediaQuery).matches;
}

if (ruleMatch) {
9 changes: 9 additions & 0 deletions test/spec/sizeMapping_spec.js
Original file line number Diff line number Diff line change
@@ -93,6 +93,15 @@ describe('sizeMapping', function () {
expect(utils.logWarn.firstCall.args[0]).to.match(/missing.+?mediaQuery/);
});

it('should log a warning message when mediaQuery property is declared as an empty string', function() {
const errorConfig = deepClone(sizeConfig);
errorConfig[0].mediaQuery = '';

sandbox.stub(utils, 'logWarn');
resolveStatus(undefined, testSizes, undefined, errorConfig);
expect(utils.logWarn.firstCall.args[0]).to.match(/missing.+?mediaQuery/);
});

it('should allow deprecated adUnit.sizes', function() {
matchMediaOverride = (str) => str === '(min-width: 1200px)' ? {matches: true} : {matches: false};