Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit 8ff9b0e

Browse files
committed
fix: incorrect merge behavior
properties in Promise should not be overwritten
1 parent b2d88c0 commit 8ff9b0e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

__tests__/helpers.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ describe('merge', () => {
2424
}
2525
})
2626
})
27+
28+
it ('should merge objects containing non-objects', () => {
29+
const a = { c: [ 1, 2, 3 ], d: Promise.resolve({ a: 1 }) }
30+
const b = { c: [ 4, 5 ], d: { b: 1 } }
31+
const c = helpers.merge(a, b)
32+
33+
expect(c).toEqual({
34+
c: [
35+
4,
36+
5,
37+
3
38+
],
39+
d: {
40+
b: 1
41+
}
42+
})
43+
})
2744
})
2845

2946
describe('getMethod', () => {

src/helpers.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export function getBasePath (base, path) {
3030

3131
export function merge (obj, src) {
3232
Object.keys(src).forEach(function (key) {
33-
if (obj[key] && typeof obj[key] === 'object') {
33+
const type = obj[key] && Object.prototype.toString.call(obj[key])
34+
35+
if (type === '[object Object]' || type === '[object Array]') {
3436
merge(obj[key], src[key])
3537
return
3638
}

0 commit comments

Comments
 (0)