Skip to content

Commit

Permalink
getFilterLimit: empty tags return 0
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgleason authored and fiatjaf committed May 30, 2024
1 parent 87a91c2 commit f8c3e20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,9 @@ describe('Filter', () => {
test('should return Infinity for empty filters', () => {
expect(getFilterLimit({})).toEqual(Infinity)
})

test('empty tags return 0', () => {
expect(getFilterLimit({ '#p': [] })).toEqual(0)
})
})
})
4 changes: 4 additions & 0 deletions filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export function getFilterLimit(filter: Filter): number {
if (filter.kinds && !filter.kinds.length) return 0
if (filter.authors && !filter.authors.length) return 0

for (const [key, value] of Object.entries(filter)) {
if (key[0] === '#' && Array.isArray(value) && !value.length) return 0
}

return Math.min(
Math.max(0, filter.limit ?? Infinity),
filter.ids?.length ?? Infinity,
Expand Down

0 comments on commit f8c3e20

Please sign in to comment.