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 2, 2024
1 parent 878e335 commit 21d6b2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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
2 changes: 1 addition & 1 deletion test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1546,8 +1546,8 @@ int main(int argc, const char *argv[]) {
test_bech32_parsing();
test_single_url_parsing();
test_url_parsing();
test_weird_note_corruption();
test_query();
test_weird_note_corruption();
test_tag_query();
test_parse_content();
test_subscriptions();
Expand Down

0 comments on commit 21d6b2b

Please sign in to comment.