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

Prebid Core : fix issue of mergeConfig #8791

Merged
merged 1 commit into from
Aug 10, 2022
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
12 changes: 6 additions & 6 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,11 @@ export function newConfig() {
option = Object.assign({}, defaults[topic], option);
}

topicalConfig[topic] = config[topic] = option;
try {
topicalConfig[topic] = config[topic] = option;
} catch (e) {
logWarn(`Cannot set config for property ${topic} : `, e)
}
});

callSubscribers(topicalConfig);
Expand Down Expand Up @@ -525,11 +529,7 @@ export function newConfig() {
return;
}

const mergedConfig = Object.keys(obj).reduce((accum, key) => {
const prevConf = _getConfig()[key] || {};
accum[key] = mergeDeep(prevConf, obj[key]);
return accum;
}, {});
const mergedConfig = mergeDeep(_getConfig(), obj);

setConfig({ ...mergedConfig });
return mergedConfig;
Expand Down
4 changes: 4 additions & 0 deletions test/spec/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ describe('config API', function () {
}

setConfig({
bidderTimeout: 2000,
ortb2: {
user: {
data: [userObj1, userObj2]
Expand All @@ -609,6 +610,7 @@ describe('config API', function () {
});

const rtd = {
bidderTimeout: 3000,
ortb2: {
user: {
data: [userObj1]
Expand All @@ -623,11 +625,13 @@ describe('config API', function () {
mergeConfig(rtd);

let ortb2Config = getConfig('ortb2');
let bidderTimeout = getConfig('bidderTimeout');

expect(ortb2Config.user.data).to.deep.include.members([userObj1, userObj2]);
expect(ortb2Config.site.content.data).to.deep.include.members([siteObj1]);
expect(ortb2Config.user.data).to.have.lengthOf(2);
expect(ortb2Config.site.content.data).to.have.lengthOf(1);
expect(bidderTimeout).to.equal(3000);
});

it('should not corrupt global configuration with bidder configuration', () => {
Expand Down