1
0
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:
Florian Bouillon 2024-01-22 01:42:59 +01:00 committed by GitHub
parent b168b86006
commit 2cfa860f6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 0 deletions

View 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
}

View File

@ -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
}