mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-22 00:59:07 -05:00
fix: postgresql tag filtering for odd-length hex-looking values
The tag filtering code misses odd-length strings that contains only hex digits [0-9a-f]. This fix makes the condition for `has_plain_values` the inverse of the condition for `has_hex_values`. Fixes #191
This commit is contained in:
parent
39a3a258a0
commit
b04ab76e73
|
@ -812,13 +812,13 @@ fn query_from_filter(f: &ReqFilter) -> Option<QueryBuilder<Postgres>> {
|
||||||
.push_bind(key.to_string())
|
.push_bind(key.to_string())
|
||||||
.push(" AND (");
|
.push(" AND (");
|
||||||
|
|
||||||
let has_plain_values = val.iter().any(|v| !is_lower_hex(v));
|
let has_plain_values = val.iter().any(|v| (v.len() % 2 != 0 || !is_lower_hex(v)));
|
||||||
let has_hex_values = val.iter().any(|v| v.len() % 2 == 0 && is_lower_hex(v));
|
let has_hex_values = val.iter().any(|v| v.len() % 2 == 0 && is_lower_hex(v));
|
||||||
if has_plain_values {
|
if has_plain_values {
|
||||||
query.push("value in (");
|
query.push("value in (");
|
||||||
// plain value match first
|
// plain value match first
|
||||||
let mut tag_query = query.separated(", ");
|
let mut tag_query = query.separated(", ");
|
||||||
for v in val.iter().filter(|v| !is_lower_hex(v)) {
|
for v in val.iter().filter(|v| v.len() % 2 != 0 || !is_lower_hex(v)) {
|
||||||
tag_query.push_bind(v.as_bytes());
|
tag_query.push_bind(v.as_bytes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user