Skip to content

Commit a7e948f

Browse files
committed
Ensure we only process true Arrays and Objects - This fixes keys with Date values
1 parent e7fdaa6 commit a7e948f

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ DotObject.prototype.dot = function (obj, tgt, path) {
438438
tgt = tgt || {}
439439
path = path || []
440440
Object.keys(obj).forEach(function (key) {
441-
if (Object(obj[key]) === obj[key]) {
441+
if (Object(obj[key]) === obj[key] && (Object.prototype.toString.call(obj[key]) === '[object Object]') || Object.prototype.toString.call(obj[key]) === '[object Array]') {
442442
return this.dot(obj[key], tgt, path.concat(key))
443443
} else {
444444
tgt[path.concat(key).join(this.seperator)] = obj[key]

src/dot-object.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ DotObject.prototype.dot = function (obj, tgt, path) {
438438
tgt = tgt || {}
439439
path = path || []
440440
Object.keys(obj).forEach(function (key) {
441-
if (Object(obj[key]) === obj[key]) {
441+
if (Object(obj[key]) === obj[key] && (Object.prototype.toString.call(obj[key]) === '[object Object]') || Object.prototype.toString.call(obj[key]) === '[object Array]') {
442442
return this.dot(obj[key], tgt, path.concat(key))
443443
} else {
444444
tgt[path.concat(key).join(this.seperator)] = obj[key]

test/dot.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ describe('dotted-key/value pairs:', function () {
2323
some: {
2424
array: ['A', 'B']
2525
},
26-
ehrm: 123
26+
ehrm: 123,
27+
dates: {
28+
first: new Date('Mon Oct 13 2014 00:00:00 GMT+0100 (BST)')
29+
}
2730
}
2831

2932
expected = {
@@ -32,7 +35,8 @@ describe('dotted-key/value pairs:', function () {
3235
'other.nested.stuff': 5,
3336
'some.array.0': 'A',
3437
'some.array.1': 'B',
35-
ehrm: 123
38+
ehrm: 123,
39+
'dates.first': new Date('Mon Oct 13 2014 00:00:00 GMT+0100 (BST)')
3640
}
3741
})
3842

0 commit comments

Comments
 (0)