@@ -104,118 +104,118 @@ function matchesKeyConstraints(object, key, constraints) {
104
104
compareTo = decode ( compareTo ) ;
105
105
}
106
106
switch ( condition ) {
107
- case '$lt' :
108
- if ( object [ key ] >= compareTo ) {
109
- return false ;
110
- }
111
- break ;
112
- case '$lte' :
113
- if ( object [ key ] > compareTo ) {
114
- return false ;
115
- }
116
- break ;
117
- case '$gt' :
118
- if ( object [ key ] <= compareTo ) {
119
- return false ;
120
- }
121
- break ;
122
- case '$gte' :
123
- if ( object [ key ] < compareTo ) {
124
- return false ;
125
- }
126
- break ;
127
- case '$ne' :
128
- if ( equalObjects ( object [ key ] , compareTo ) ) {
129
- return false ;
130
- }
131
- break ;
132
- case '$in' :
133
- if ( ! contains ( compareTo , object [ key ] ) ) {
134
- return false ;
135
- }
136
- break ;
137
- case '$nin' :
138
- if ( contains ( compareTo , object [ key ] ) ) {
107
+ case '$lt' :
108
+ if ( object [ key ] >= compareTo ) {
109
+ return false ;
110
+ }
111
+ break ;
112
+ case '$lte' :
113
+ if ( object [ key ] > compareTo ) {
114
+ return false ;
115
+ }
116
+ break ;
117
+ case '$gt' :
118
+ if ( object [ key ] <= compareTo ) {
119
+ return false ;
120
+ }
121
+ break ;
122
+ case '$gte' :
123
+ if ( object [ key ] < compareTo ) {
124
+ return false ;
125
+ }
126
+ break ;
127
+ case '$ne' :
128
+ if ( equalObjects ( object [ key ] , compareTo ) ) {
129
+ return false ;
130
+ }
131
+ break ;
132
+ case '$in' :
133
+ if ( ! contains ( compareTo , object [ key ] ) ) {
134
+ return false ;
135
+ }
136
+ break ;
137
+ case '$nin' :
138
+ if ( contains ( compareTo , object [ key ] ) ) {
139
+ return false ;
140
+ }
141
+ break ;
142
+ case '$all' :
143
+ for ( i = 0 ; i < compareTo . length ; i ++ ) {
144
+ if ( object [ key ] . indexOf ( compareTo [ i ] ) < 0 ) {
139
145
return false ;
140
146
}
147
+ }
148
+ break ;
149
+ case '$exists' :
150
+ {
151
+ const propertyExists = typeof object [ key ] !== 'undefined' ;
152
+ const existenceIsRequired = constraints [ '$exists' ] ;
153
+ if ( typeof constraints [ '$exists' ] !== 'boolean' ) {
154
+ // The SDK will never submit a non-boolean for $exists, but if someone
155
+ // tries to submit a non-boolean for $exits outside the SDKs, just ignore it.
141
156
break ;
142
- case '$all' :
143
- for ( i = 0 ; i < compareTo . length ; i ++ ) {
144
- if ( object [ key ] . indexOf ( compareTo [ i ] ) < 0 ) {
145
- return false ;
146
- }
147
- }
148
- break ;
149
- case '$exists' :
150
- {
151
- const propertyExists = typeof object [ key ] !== 'undefined' ;
152
- const existenceIsRequired = constraints [ '$exists' ] ;
153
- if ( typeof constraints [ '$exists' ] !== 'boolean' ) {
154
- // The SDK will never submit a non-boolean for $exists, but if someone
155
- // tries to submit a non-boolean for $exits outside the SDKs, just ignore it.
156
- break ;
157
- }
158
- if ( ! propertyExists && existenceIsRequired || propertyExists && ! existenceIsRequired ) {
159
- return false ;
160
- }
161
- break ;
162
- }
163
- case '$regex' :
164
- if ( typeof compareTo === 'object' ) {
165
- return compareTo . test ( object [ key ] ) ;
157
+ }
158
+ if ( ! propertyExists && existenceIsRequired || propertyExists && ! existenceIsRequired ) {
159
+ return false ;
160
+ }
161
+ break ;
162
+ }
163
+ case '$regex' :
164
+ if ( typeof compareTo === 'object' ) {
165
+ return compareTo . test ( object [ key ] ) ;
166
+ }
167
+ // JS doesn't support perl-style escaping
168
+ var expString = '' ;
169
+ var escapeEnd = - 2 ;
170
+ var escapeStart = compareTo . indexOf ( '\\Q' ) ;
171
+ while ( escapeStart > - 1 ) {
172
+ // Add the unescaped portion
173
+ expString += compareTo . substring ( escapeEnd + 2 , escapeStart ) ;
174
+ escapeEnd = compareTo . indexOf ( '\\E' , escapeStart ) ;
175
+ if ( escapeEnd > - 1 ) {
176
+ expString += compareTo . substring ( escapeStart + 2 , escapeEnd ) . replace ( / \\ \\ \\ \\ E / g, '\\E' ) . replace ( / \W / g, '\\$&' ) ;
166
177
}
167
- // JS doesn't support perl-style escaping
168
- var expString = '' ;
169
- var escapeEnd = - 2 ;
170
- var escapeStart = compareTo . indexOf ( '\\Q' ) ;
171
- while ( escapeStart > - 1 ) {
172
- // Add the unescaped portion
173
- expString += compareTo . substring ( escapeEnd + 2 , escapeStart ) ;
174
- escapeEnd = compareTo . indexOf ( '\\E' , escapeStart ) ;
175
- if ( escapeEnd > - 1 ) {
176
- expString += compareTo . substring ( escapeStart + 2 , escapeEnd ) . replace ( / \\ \\ \\ \\ E / g, '\\E' ) . replace ( / \W / g, '\\$&' ) ;
177
- }
178
178
179
- escapeStart = compareTo . indexOf ( '\\Q' , escapeEnd ) ;
180
- }
181
- expString += compareTo . substring ( Math . max ( escapeStart , escapeEnd + 2 ) ) ;
182
- var exp = new RegExp ( expString , constraints . $options || '' ) ;
183
- if ( ! exp . test ( object [ key ] ) ) {
184
- return false ;
185
- }
186
- break ;
187
- case '$nearSphere' :
188
- if ( ! compareTo || ! object [ key ] ) {
189
- return false ;
190
- }
191
- var distance = compareTo . radiansTo ( object [ key ] ) ;
192
- var max = constraints . $maxDistance || Infinity ;
193
- return distance <= max ;
194
- case '$within' :
195
- if ( ! compareTo || ! object [ key ] ) {
196
- return false ;
197
- }
198
- var southWest = compareTo . $box [ 0 ] ;
199
- var northEast = compareTo . $box [ 1 ] ;
200
- if ( southWest . latitude > northEast . latitude || southWest . longitude > northEast . longitude ) {
201
- // Invalid box, crosses the date line
202
- return false ;
203
- }
204
- return object [ key ] . latitude > southWest . latitude && object [ key ] . latitude < northEast . latitude && object [ key ] . longitude > southWest . longitude && object [ key ] . longitude < northEast . longitude ;
205
- case '$options' :
206
- // Not a query type, but a way to add options to $regex. Ignore and
207
- // avoid the default
208
- break ;
209
- case '$maxDistance' :
210
- // Not a query type, but a way to add a cap to $nearSphere. Ignore and
211
- // avoid the default
212
- break ;
213
- case '$select' :
179
+ escapeStart = compareTo . indexOf ( '\\Q' , escapeEnd ) ;
180
+ }
181
+ expString += compareTo . substring ( Math . max ( escapeStart , escapeEnd + 2 ) ) ;
182
+ var exp = new RegExp ( expString , constraints . $options || '' ) ;
183
+ if ( ! exp . test ( object [ key ] ) ) {
214
184
return false ;
215
- case '$dontSelect' :
185
+ }
186
+ break ;
187
+ case '$nearSphere' :
188
+ if ( ! compareTo || ! object [ key ] ) {
216
189
return false ;
217
- default :
190
+ }
191
+ var distance = compareTo . radiansTo ( object [ key ] ) ;
192
+ var max = constraints . $maxDistance || Infinity ;
193
+ return distance <= max ;
194
+ case '$within' :
195
+ if ( ! compareTo || ! object [ key ] ) {
196
+ return false ;
197
+ }
198
+ var southWest = compareTo . $box [ 0 ] ;
199
+ var northEast = compareTo . $box [ 1 ] ;
200
+ if ( southWest . latitude > northEast . latitude || southWest . longitude > northEast . longitude ) {
201
+ // Invalid box, crosses the date line
218
202
return false ;
203
+ }
204
+ return object [ key ] . latitude > southWest . latitude && object [ key ] . latitude < northEast . latitude && object [ key ] . longitude > southWest . longitude && object [ key ] . longitude < northEast . longitude ;
205
+ case '$options' :
206
+ // Not a query type, but a way to add options to $regex. Ignore and
207
+ // avoid the default
208
+ break ;
209
+ case '$maxDistance' :
210
+ // Not a query type, but a way to add a cap to $nearSphere. Ignore and
211
+ // avoid the default
212
+ break ;
213
+ case '$select' :
214
+ return false ;
215
+ case '$dontSelect' :
216
+ return false ;
217
+ default :
218
+ return false ;
219
219
}
220
220
}
221
221
return true ;
0 commit comments