Skip to content

Commit

Permalink
Ensure we only process true Arrays and Objects - This fixes keys with…
Browse files Browse the repository at this point in the history
… Date values
  • Loading branch information
MechJosh0 committed Aug 4, 2016
1 parent e7fdaa6 commit a7e948f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ DotObject.prototype.dot = function (obj, tgt, path) {
tgt = tgt || {}
path = path || []
Object.keys(obj).forEach(function (key) {
if (Object(obj[key]) === obj[key]) {
if (Object(obj[key]) === obj[key] && (Object.prototype.toString.call(obj[key]) === '[object Object]') || Object.prototype.toString.call(obj[key]) === '[object Array]') {
return this.dot(obj[key], tgt, path.concat(key))
} else {
tgt[path.concat(key).join(this.seperator)] = obj[key]
Expand Down
2 changes: 1 addition & 1 deletion src/dot-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ DotObject.prototype.dot = function (obj, tgt, path) {
tgt = tgt || {}
path = path || []
Object.keys(obj).forEach(function (key) {
if (Object(obj[key]) === obj[key]) {
if (Object(obj[key]) === obj[key] && (Object.prototype.toString.call(obj[key]) === '[object Object]') || Object.prototype.toString.call(obj[key]) === '[object Array]') {
return this.dot(obj[key], tgt, path.concat(key))
} else {
tgt[path.concat(key).join(this.seperator)] = obj[key]
Expand Down
8 changes: 6 additions & 2 deletions test/dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ describe('dotted-key/value pairs:', function () {
some: {
array: ['A', 'B']
},
ehrm: 123
ehrm: 123,
dates: {
first: new Date('Mon Oct 13 2014 00:00:00 GMT+0100 (BST)')
}
}

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

Expand Down

0 comments on commit a7e948f

Please sign in to comment.