Skip to content

Commit

Permalink
Fix issue where id tag filters are pushed as strings
Browse files Browse the repository at this point in the history
When creating filters, sometimes IDs are pushed as strings, so if there
is ever a 0 byte, the id prematurely ends, causing the filter to not
match

Fixes: rust-nostr/nostr#454
Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
jb55 committed Aug 1, 2024
1 parent 878e335 commit 087e201
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/nostrdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,18 @@ static int ndb_filter_add_element(struct ndb_filter *filter, union ndb_filter_el
offset = el.integer;
break;
case NDB_FILTER_TAGS:
if (!cursor_push_c_str(&filter->data_buf, el.string))
switch (current->field.elem_type) {
case NDB_ELEMENT_ID:
if (!cursor_push(&filter->data_buf, (unsigned char *)el.id, 32))
return 0;
break;
case NDB_ELEMENT_STRING:
if (!cursor_push_c_str(&filter->data_buf, el.string))
return 0;
break;
case NDB_ELEMENT_UNKNOWN:
return 0;
}
// push a pointer of the string in the databuf as an element
break;
}
Expand Down

0 comments on commit 087e201

Please sign in to comment.