File tree 3 files changed +16
-2
lines changed 3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 3
3
## [ Unreleased]
4
4
5
5
* Drop Node 0.12 support
6
+ * Prevent ` TypeError ` when a filter is applied on a ` null ` value [ #510 ] ( https://github.com/typicode/json-server/issues/510 )
6
7
7
8
## [ 0.9.6] [ 2016-03-08 ]
8
9
Original file line number Diff line number Diff line change @@ -114,9 +114,12 @@ module.exports = (db, name) => {
114
114
const isRange = / _ l t e $ / . test ( key ) || / _ g t e $ / . test ( key )
115
115
const isLike = / _ l i k e $ / . test ( key )
116
116
const path = key . replace ( / ( _ l t e | _ g t e | _ n e | _ l i k e ) $ / , '' )
117
+ // get item value based on path
118
+ // i.e post.title -> 'foo'
117
119
const elementValue = _ . get ( element , path )
118
120
119
- if ( elementValue === undefined ) {
121
+ // Prevent toString() failing on undefined or null values
122
+ if ( elementValue === undefined || elementValue === null ) {
120
123
return
121
124
}
122
125
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ describe('Server', () => {
20
20
21
21
db . posts = [
22
22
{ id : 1 , body : 'foo' } ,
23
- { id : 2 , body : 'bar' }
23
+ { id : 2 , body : 'bar' } ,
24
24
]
25
25
26
26
db . tags = [
@@ -163,6 +163,16 @@ describe('Server', () => {
163
163
. expect ( db . comments )
164
164
. expect ( 200 )
165
165
) )
166
+
167
+ // https://github.com/typicode/json-server/issues/510
168
+ it . only ( 'should not fail with null value' , ( ) => {
169
+ db . posts . push ( { id : 99 , body : null } )
170
+ return request ( server )
171
+ . get ( '/posts?body=foo' )
172
+ . expect ( 'Content-Type' , / j s o n / )
173
+ . expect ( [ db . posts [ 0 ] ] )
174
+ . expect ( 200 )
175
+ } )
166
176
} )
167
177
168
178
describe ( 'GET /:resource?q=' , ( ) => {
You can’t perform that action at this time.
0 commit comments