Skip to content

Commit

Permalink
Fix bug where arrays were altered during date casting
Browse files Browse the repository at this point in the history
  • Loading branch information
kjellmorten committed Apr 5, 2018
1 parent 98ae4df commit e2942e9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
19 changes: 19 additions & 0 deletions lib/adapter/prepareFilter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,22 @@ test('should not touch Date object when casting', (t) => {

t.deepEqual(ret, expected)
})

test('should not touch arrays when casting', (t) => {
const params = {
type: 'entry',
query: {_id: {$in: ['entry:ent1', 'entry:ent2']}}
}
const endpoint = {
collection: 'documents',
db: 'database'
}
const expected = {
type: 'entry',
_id: {$in: ['entry:ent1', 'entry:ent2']}
}

const ret = prepareFilter(params, endpoint, params)

t.deepEqual(ret, expected)
})
3 changes: 2 additions & 1 deletion lib/adapter/prepareFilter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const dotprop = require('dot-prop')
const is = require('@sindresorhus/is')

const setTypeOrId = (query, type, id) => {
if (Object.keys(query).length === 0) {
Expand All @@ -10,7 +11,7 @@ const setTypeOrId = (query, type, id) => {
}
}

const isSubObject = (value) => (value && typeof value === 'object' && Object.keys(value).length)
const isSubObject = (value) => is.plainObject(value)
const dateStringRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?([+-]\d{2}:\d{2}|Z)$/
const isDateString = (value) => typeof value === 'string' && dateStringRegex.test(value)
const castValueIfDate = (value) => (isDateString(value))
Expand Down
13 changes: 9 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "integreat-adapter-mongodb",
"version": "0.1.6",
"version": "0.1.7",
"description": "Integreat adapter for mongodb",
"main": "index.js",
"author": "Kjell-Morten Bratsberg Thorsen <post@kjellmorten.no>",
Expand Down Expand Up @@ -49,6 +49,7 @@
"npm": ">= 5.4"
},
"dependencies": {
"@sindresorhus/is": "^0.8.0",
"dot-prop": "^4.2.0",
"mongodb": "^3.0.5"
},
Expand All @@ -57,7 +58,7 @@
"babel-preset-env": "^1.6.1",
"coveralls": "^3.0.0",
"nyc": "^11.6.0",
"sinon": "^4.4.9",
"sinon": "^4.5.0",
"standard": "^11.0.1"
}
}

0 comments on commit e2942e9

Please sign in to comment.