Merge pull request #1921 from LemmyNet/fix_login

Fix login ilike bug. Fixes #1920
required_public_key
Nutomic 2021-11-22 13:05:57 +00:00 committed by GitHub
commit 88e81dce6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 7 deletions

View File

@ -5,7 +5,7 @@ use crate::{
source::person::{Person, PersonForm}, source::person::{Person, PersonForm},
traits::Crud, traits::Crud,
}; };
use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl, *}; use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
use url::Url; use url::Url;
mod safe_type { mod safe_type {
@ -194,7 +194,7 @@ impl Person {
person person
.filter(deleted.eq(false)) .filter(deleted.eq(false))
.filter(local.eq(true)) .filter(local.eq(true))
.filter(name.ilike(from_name)) .filter(name.eq(from_name))
.first::<Person>(conn) .first::<Person>(conn)
} }

View File

@ -70,7 +70,7 @@ pub fn from_opt_str_to_opt_enum<T: std::str::FromStr>(opt: &Option<String>) -> O
} }
pub fn fuzzy_search(q: &str) -> String { pub fn fuzzy_search(q: &str) -> String {
let replaced = q.replace(" ", "%"); let replaced = q.replace("%", "\\%").replace("_", "\\_").replace(" ", "%");
format!("%{}%", replaced) format!("%{}%", replaced)
} }
@ -154,8 +154,11 @@ mod tests {
#[test] #[test]
fn test_fuzzy_search() { fn test_fuzzy_search() {
let test = "This is a fuzzy search"; let test = "This %is% _a_ fuzzy search";
assert_eq!(fuzzy_search(test), "%This%is%a%fuzzy%search%".to_string()); assert_eq!(
fuzzy_search(test),
"%This%\\%is\\%%\\_a\\_%fuzzy%search%".to_string()
);
} }
#[test] #[test]

View File

@ -82,8 +82,8 @@ impl LocalUserView {
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id))) .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
.filter( .filter(
person::name person::name
.ilike(name_or_email) .eq(name_or_email)
.or(local_user::email.ilike(name_or_email)), .or(local_user::email.eq(name_or_email)),
) )
.select(( .select((
local_user::all_columns, local_user::all_columns,