From b04ab76e7305eb7585e94c20c5cd72e694cf9a20 Mon Sep 17 00:00:00 2001 From: Laszlo Megyer Date: Sat, 30 Mar 2024 21:22:37 +0000 Subject: [PATCH] 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 --- src/repo/postgres.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/repo/postgres.rs b/src/repo/postgres.rs index dd120ab..5a1a28b 100644 --- a/src/repo/postgres.rs +++ b/src/repo/postgres.rs @@ -812,13 +812,13 @@ fn query_from_filter(f: &ReqFilter) -> Option> { .push_bind(key.to_string()) .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)); if has_plain_values { query.push("value in ("); // plain value match first 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()); } }