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

fix: loosing request header (#4858) #4871

Merged
merged 2 commits into from
Sep 26, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/core/mergeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module.exports = function mergeConfig(config1, config2) {
function getMergedValue(target, source) {
if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
return utils.merge(target, source);
} else if (utils.isEmptyObject(source)) {
return utils.merge({}, target);
} else if (utils.isPlainObject(source)) {
return utils.merge({}, source);
} else if (utils.isArray(source)) {
Expand Down
11 changes: 11 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ function isPlainObject(val) {
return prototype === null || prototype === Object.prototype;
}

/**
* Determine if a value is a empty Object
*
* @param {Object} val The value to test
* @return {boolean} True if value is a empty Object, otherwise false
*/
function isEmptyObject(val) {
return val && Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
}

/**
* Determine if a value is a Date
*
Expand Down Expand Up @@ -483,6 +493,7 @@ module.exports = {
isNumber: isNumber,
isObject: isObject,
isPlainObject: isPlainObject,
isEmptyObject: isEmptyObject,
isUndefined: isUndefined,
isDate: isDate,
isFile: isFile,
Expand Down
16 changes: 16 additions & 0 deletions test/specs/core/mergeConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,22 @@ describe('core::mergeConfig', function() {
.toEqual({validateStatus: {a: 1, b: 2, c: 2}});
});

it('should merge if config1 is class object', function() {
class Header {};
var validateStatus = new Header();
validateStatus["X-Foo"] = "bar";
var merged = mergeConfig({validateStatus: validateStatus}, {validateStatus: {}});
expect(JSON.stringify(merged.validateStatus)).toBe(JSON.stringify(validateStatus));
});

it('should merge if config2 is class object', function() {
class Header {};
var validateStatus = new Header();
validateStatus["X-Foo"] = "bar";
var merged = mergeConfig({validateStatus: {}}, {validateStatus: validateStatus});
expect(JSON.stringify(merged.validateStatus)).toBe(JSON.stringify(validateStatus));
});

it('should clone config2 if is plain object', function() {
var config1 = {validateStatus: [1, 2, 3]};
var config2 = {validateStatus: {a: 1, b: 2}};
Expand Down