From e13275d07c6795c4cf07ccf6273dfe06dc8448d9 Mon Sep 17 00:00:00 2001 From: Doug Hoyte Date: Tue, 6 Jun 2023 15:33:03 -0400 Subject: [PATCH] allow filtering on empty tag values --- src/filters.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/filters.h b/src/filters.h index b7398a6..22a82d3 100644 --- a/src/filters.h +++ b/src/filters.h @@ -49,8 +49,6 @@ struct FilterSetBytes { } bool doesMatch(std::string_view candidate) const { - if (candidate.size() == 0) throw herr("invalid candidate"); - // Binary search for upper-bound: https://en.cppreference.com/w/cpp/algorithm/upper_bound ssize_t first = 0, last = items.size(), curr; @@ -61,7 +59,7 @@ struct FilterSetBytes { step = count / 2; curr += step; - bool comp = (uint8_t)candidate[0] != items[curr].firstByte + bool comp = (candidate.size() && items[curr].size && (uint8_t)candidate[0] != items[curr].firstByte) ? (uint8_t)candidate[0] < items[curr].firstByte : candidate < std::string_view(buf.data() + items[curr].offset, items[curr].size); @@ -145,7 +143,7 @@ struct NostrFilter { if (tag == 'p' || tag == 'e') { tags.emplace(tag, FilterSetBytes(v, true, 32, 32)); } else { - tags.emplace(tag, FilterSetBytes(v, false, 1, MAX_INDEXED_TAG_VAL_SIZE)); + tags.emplace(tag, FilterSetBytes(v, false, 0, MAX_INDEXED_TAG_VAL_SIZE)); } } else { throw herr("unindexed tag filter");