nestjs-paginate
nestjs-paginate copied to clipboard
$eq operator is broken with certain string values
Steps to reproduce
Perform a filter query with an $eq
filter with a string that contains "what JS believes to be a number, but that is actually a string"™
For example, filter.referenceId
= $eq:651581942751358e5
Expected result
Elements with the given filter are found.
Actual result
No elements are found
Additional notes
This regression was introduced in #952. It happens because the above string passes the Number.isNumber
check, even though the value is not meant to be a number.
In the example above:
const myString = '651581942751358e5'
console.log(Number.isNaN(myString)) // false
console.log(Number(myString)) // 65158194275135800000
The Number()
conversion is not problematic with values that are actually numbers - but unfortunately JS has a loose interpretation of which strings actually qualify as numbers.