mirror of
https://github.com/tcgdex/cards-database.git
synced 2025-04-23 03:12:10 +00:00
fix: Undefined values crashing the request (#476)
This commit is contained in:
parent
b168b86006
commit
2cfa860f6d
25
.bruno/fixes/474-queries-crashing-the-server.bru
Normal file
25
.bruno/fixes/474-queries-crashing-the-server.bru
Normal file
@ -0,0 +1,25 @@
|
||||
meta {
|
||||
name: 474 - Queries crashing the server
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{BASE_URL}}/v2/en/cards?legal.standard=true
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
query {
|
||||
legal.standard: true
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
}
|
||||
|
||||
docs {
|
||||
Validate the issue seen in
|
||||
|
||||
https://github.com/tcgdex/cards-database/issues/474
|
||||
}
|
@ -68,6 +68,11 @@ export function validateItem(validator: any | Array<any>, value: any, strict: bo
|
||||
validator = parseInt(validator)
|
||||
}
|
||||
|
||||
// do a comparaison with null values
|
||||
if (isNull(value)) {
|
||||
return isNull(validator)
|
||||
}
|
||||
|
||||
if (typeof value === 'object') {
|
||||
// invert signal so that an early exit mean that a match was found!
|
||||
return !objectLoop(value, (v) => {
|
||||
@ -210,3 +215,14 @@ export function handleValidation(data: Array<any>, query: Query) {
|
||||
return validateItem(valueToValidate, v[key], query.strict)
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* validate that the value is null or undefined
|
||||
* @param value the value the check
|
||||
* @returns if the value is undefined or null or not
|
||||
*/
|
||||
function isNull(value: any): value is (undefined | null) {
|
||||
return typeof value === 'undefined' || value === null
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user