Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter hotfix 9 21 23 #14

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-shoes-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rabbitholegg/questdk": patch
---

Handle undefined and non-existent key in filter better so $some doesn't fail
17 changes: 13 additions & 4 deletions src/filter/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,19 @@ export function apply(

if (key in operators) {
const operator = operators[key as OperatorKey]
if (!operator(context, filters[key])) return false
if (!operator(context, filters[key])) {
return false
}
continue
}

if (typeof filters[key] === 'object') {
if (!apply(context[key], filters[key])) return false
if (!(key in context)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch

return false
}
if (!apply(context[key], filters[key])) {
return false
}
} else if (isAddress(context[key])) {
if (context[key].toLowerCase() !== filters[key].toLowerCase()) {
return false
Expand All @@ -253,13 +260,15 @@ export function apply(
typeof context[key] === 'bigint' ||
typeof context[key] === 'number'
) {
if (BigInt(context[key]) !== BigInt(filters[key])) {
if (
context[key] === undefined ||
BigInt(context[key]) !== BigInt(filters[key])
) {
return false
}
} else if (context[key] !== filters[key]) {
return false
}
}

return true
}