Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,8 @@ VALUES (?, ?, ?, ?, ?, ?)
Origin::IncomingReplyTo
};
if query.is_some() {
let s3str_like_cmd = format!("%{}%", query.unwrap_or("").to_lowercase());
let query_lowercased = query.unwrap_or("").to_lowercase();
let s3str_like_cmd = format!("%{}%", query_lowercased);
context
.sql
.query_map(
Expand All @@ -1151,7 +1152,7 @@ ORDER BY c.last_seen DESC, c.id DESC
flag_address,
minimal_origin,
&s3str_like_cmd,
&s3str_like_cmd,
&query_lowercased,
),
|row| {
let id: ContactId = row.get(0)?;
Expand Down
7 changes: 6 additions & 1 deletion src/contact/contact_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@ async fn test_get_contacts() -> Result<()> {
assert_eq!(contacts.len(), 1);
assert_eq!(contacts.first(), Some(&id));

// Search by address.
// Search by address is case-insensitive, but only returns direct matches.
let contacts = Contact::get_all(&context, 0, Some("alice@example.org")).await?;
assert_eq!(contacts.len(), 1);
assert_eq!(contacts.first(), Some(&id));
let contacts = Contact::get_all(&context, 0, Some("Alice@example.org")).await?;
assert_eq!(contacts.len(), 1);
assert_eq!(contacts.first(), Some(&id));
let contacts = Contact::get_all(&context, 0, Some("alice@")).await?;
assert_eq!(contacts.len(), 0);

let contacts = Contact::get_all(&context, 0, Some("Foobar")).await?;
assert_eq!(contacts.len(), 0);
Expand Down