From: Kradyz <81911574+Kradyz@users.noreply.github.com> Date: Mon, 20 Dec 2021 22:23:06 +0000 (+0100) Subject: Case-insensitive webfinger response. Fixes #1955 & #1986 (#2005) X-Git-Url: http://these/git/%24%7BgetStaticDir%28%29%7D/js/static/%24%7BappleTouchIcon%7D?a=commitdiff_plain;h=9f64872d5ac07b5f7ffde673ed00d30362b178c4;p=lemmy.git Case-insensitive webfinger response. Fixes #1955 & #1986 (#2005) * Make webfinger case insensitive * Make webfinger case insensitive * Case insensitive domain name * Case-insensitive webfinger * formatting Co-authored-by: Kradyz --- diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index 87b2991b..1eec6dcf 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -649,7 +649,7 @@ export function wrapper(form: any): string { export function randomString(length: number): string { var result = ''; - var characters = 'abcdefghijklmnopqrstuvwxyz0123456789_'; + var characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'; var charactersLength = characters.length; for (var i = 0; i < length; i++) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index e6b795e9..ea3c76c4 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -8,6 +8,8 @@ homepage = "https://join-lemmy.org/" documentation = "https://join-lemmy.org/docs/en/index.html" [lib] +name = "lemmy_db_schema" +path = "src/lib.rs" doctest = false [dependencies] diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index 8adf2ba5..19a3a954 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -1,4 +1,5 @@ use crate::{ + functions::lower, naive_now, newtypes::{CommunityId, DbUrl, PersonId}, source::community::{ @@ -95,7 +96,7 @@ impl Community { use crate::schema::community::dsl::*; community .filter(local.eq(true)) - .filter(name.eq(community_name)) + .filter(lower(name).eq(lower(community_name))) .first::(conn) } diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index 5e0048ec..f09cdfa0 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -1,4 +1,5 @@ use crate::{ + functions::lower, naive_now, newtypes::{DbUrl, PersonId}, schema::person::dsl::*, @@ -194,7 +195,7 @@ impl Person { person .filter(deleted.eq(false)) .filter(local.eq(true)) - .filter(name.eq(from_name)) + .filter(lower(name).eq(lower(from_name))) .first::(conn) } diff --git a/crates/db_schema/src/lib.rs b/crates/db_schema/src/lib.rs index fe58464a..e726aaa5 100644 --- a/crates/db_schema/src/lib.rs +++ b/crates/db_schema/src/lib.rs @@ -143,6 +143,8 @@ pub mod functions { sql_function! { fn hot_rank(score: BigInt, time: Timestamp) -> Integer; } + + sql_function!(fn lower(x: Text) -> Text); } #[cfg(test)] diff --git a/crates/utils/src/settings/mod.rs b/crates/utils/src/settings/mod.rs index de194090..92c9fb01 100644 --- a/crates/utils/src/settings/mod.rs +++ b/crates/utils/src/settings/mod.rs @@ -13,7 +13,7 @@ static SETTINGS: Lazy> = Lazy::new(|| RwLock::new(Settings::init().expect("Failed to load settings file"))); static WEBFINGER_REGEX: Lazy = Lazy::new(|| { Regex::new(&format!( - "^acct:([a-z0-9_]{{3,}})@{}$", + "^acct:([a-zA-Z0-9_]{{3,}})@{}$", Settings::get().hostname )) .expect("compile webfinger regex")