]> Untitled Git - lemmy.git/commitdiff
Case-insensitive webfinger response. Fixes #1955 & #1986 (#2005)
authorKradyz <81911574+Kradyz@users.noreply.github.com>
Mon, 20 Dec 2021 22:23:06 +0000 (23:23 +0100)
committerGitHub <noreply@github.com>
Mon, 20 Dec 2021 22:23:06 +0000 (17:23 -0500)
* Make webfinger case insensitive

* Make webfinger case insensitive

* Case insensitive domain name

* Case-insensitive webfinger

* formatting

Co-authored-by: Kradyz <k@radiz.nl>
api_tests/src/shared.ts
crates/db_schema/Cargo.toml
crates/db_schema/src/impls/community.rs
crates/db_schema/src/impls/person.rs
crates/db_schema/src/lib.rs
crates/utils/src/settings/mod.rs

index 87b2991b8633672d1f4015fdc4724a8bd3478981..1eec6dcfb3fa38cbb5e164bca70c34c314db6b4b 100644 (file)
@@ -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));
index e6b795e9c994d85079ca8cc9bb07d2f787495631..ea3c76c4590b777f5f9ec4fbd020ad4d4324d6f0 100644 (file)
@@ -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]
index 8adf2ba5778c68e76637e8387bbb1f8eca2cdd6b..19a3a95486f583d17596321335972aa5b2e6cd61 100644 (file)
@@ -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::<Self>(conn)
   }
 
index 5e0048ecf1bd7f42a106eddcf02951c53edb1634..f09cdfa0eef5b2dde0ce241b4e7d2544d63040c1 100644 (file)
@@ -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::<Person>(conn)
   }
 
index fe58464afd886aecf649cb6d5a3e10fff0f888b3..e726aaa5bdeac22ec437ddc880940f7fb0f6b36e 100644 (file)
@@ -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)]
index de1940902e658927f6f91609081083d04656b72a..92c9fb01f308573185e0a44b37e5f1e383f1054d 100644 (file)
@@ -13,7 +13,7 @@ static SETTINGS: Lazy<RwLock<Settings>> =
   Lazy::new(|| RwLock::new(Settings::init().expect("Failed to load settings file")));
 static WEBFINGER_REGEX: Lazy<Regex> = Lazy::new(|| {
   Regex::new(&format!(
-    "^acct:([a-z0-9_]{{3,}})@{}$",
+    "^acct:([a-zA-Z0-9_]{{3,}})@{}$",
     Settings::get().hostname
   ))
   .expect("compile webfinger regex")