mirror of
https://github.com/typicode/json-server.git
synced 2025-07-30 13:42:11 +08:00
Fix #510 thanks to @robinvenneman
This commit is contained in:
@ -3,6 +3,7 @@
|
|||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
* Drop Node 0.12 support
|
* Drop Node 0.12 support
|
||||||
|
* Prevent `TypeError` when a filter is applied on a `null` value [#510](https://github.com/typicode/json-server/issues/510)
|
||||||
|
|
||||||
## [0.9.6][2016-03-08]
|
## [0.9.6][2016-03-08]
|
||||||
|
|
||||||
|
@ -114,9 +114,12 @@ module.exports = (db, name) => {
|
|||||||
const isRange = /_lte$/.test(key) || /_gte$/.test(key)
|
const isRange = /_lte$/.test(key) || /_gte$/.test(key)
|
||||||
const isLike = /_like$/.test(key)
|
const isLike = /_like$/.test(key)
|
||||||
const path = key.replace(/(_lte|_gte|_ne|_like)$/, '')
|
const path = key.replace(/(_lte|_gte|_ne|_like)$/, '')
|
||||||
|
// get item value based on path
|
||||||
|
// i.e post.title -> 'foo'
|
||||||
const elementValue = _.get(element, path)
|
const elementValue = _.get(element, path)
|
||||||
|
|
||||||
if (elementValue === undefined) {
|
// Prevent toString() failing on undefined or null values
|
||||||
|
if (elementValue === undefined || elementValue === null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ describe('Server', () => {
|
|||||||
|
|
||||||
db.posts = [
|
db.posts = [
|
||||||
{ id: 1, body: 'foo' },
|
{ id: 1, body: 'foo' },
|
||||||
{ id: 2, body: 'bar' }
|
{ id: 2, body: 'bar' },
|
||||||
]
|
]
|
||||||
|
|
||||||
db.tags = [
|
db.tags = [
|
||||||
@ -163,6 +163,16 @@ describe('Server', () => {
|
|||||||
.expect(db.comments)
|
.expect(db.comments)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
// https://github.com/typicode/json-server/issues/510
|
||||||
|
it.only('should not fail with null value', () => {
|
||||||
|
db.posts.push({ id: 99, body: null })
|
||||||
|
return request(server)
|
||||||
|
.get('/posts?body=foo')
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect([ db.posts[0] ])
|
||||||
|
.expect(200)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('GET /:resource?q=', () => {
|
describe('GET /:resource?q=', () => {
|
||||||
|
Reference in New Issue
Block a user