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 <k@radiz.nl>
This commit is contained in:
Kradyz 2021-12-20 23:23:06 +01:00 committed by GitHub
parent c883a49a40
commit 9f64872d5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 4 deletions

View file

@ -649,7 +649,7 @@ export function wrapper(form: any): string {
export function randomString(length: number): string { export function randomString(length: number): string {
var result = ''; var result = '';
var characters = 'abcdefghijklmnopqrstuvwxyz0123456789_'; var characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
var charactersLength = characters.length; var charactersLength = characters.length;
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength)); result += characters.charAt(Math.floor(Math.random() * charactersLength));

View file

@ -8,6 +8,8 @@ homepage = "https://join-lemmy.org/"
documentation = "https://join-lemmy.org/docs/en/index.html" documentation = "https://join-lemmy.org/docs/en/index.html"
[lib] [lib]
name = "lemmy_db_schema"
path = "src/lib.rs"
doctest = false doctest = false
[dependencies] [dependencies]

View file

@ -1,4 +1,5 @@
use crate::{ use crate::{
functions::lower,
naive_now, naive_now,
newtypes::{CommunityId, DbUrl, PersonId}, newtypes::{CommunityId, DbUrl, PersonId},
source::community::{ source::community::{
@ -95,7 +96,7 @@ impl Community {
use crate::schema::community::dsl::*; use crate::schema::community::dsl::*;
community community
.filter(local.eq(true)) .filter(local.eq(true))
.filter(name.eq(community_name)) .filter(lower(name).eq(lower(community_name)))
.first::<Self>(conn) .first::<Self>(conn)
} }

View file

@ -1,4 +1,5 @@
use crate::{ use crate::{
functions::lower,
naive_now, naive_now,
newtypes::{DbUrl, PersonId}, newtypes::{DbUrl, PersonId},
schema::person::dsl::*, schema::person::dsl::*,
@ -194,7 +195,7 @@ impl Person {
person person
.filter(deleted.eq(false)) .filter(deleted.eq(false))
.filter(local.eq(true)) .filter(local.eq(true))
.filter(name.eq(from_name)) .filter(lower(name).eq(lower(from_name)))
.first::<Person>(conn) .first::<Person>(conn)
} }

View file

@ -143,6 +143,8 @@ pub mod functions {
sql_function! { sql_function! {
fn hot_rank(score: BigInt, time: Timestamp) -> Integer; fn hot_rank(score: BigInt, time: Timestamp) -> Integer;
} }
sql_function!(fn lower(x: Text) -> Text);
} }
#[cfg(test)] #[cfg(test)]

View file

@ -13,7 +13,7 @@ static SETTINGS: Lazy<RwLock<Settings>> =
Lazy::new(|| RwLock::new(Settings::init().expect("Failed to load settings file"))); Lazy::new(|| RwLock::new(Settings::init().expect("Failed to load settings file")));
static WEBFINGER_REGEX: Lazy<Regex> = Lazy::new(|| { static WEBFINGER_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(&format!( Regex::new(&format!(
"^acct:([a-z0-9_]{{3,}})@{}$", "^acct:([a-zA-Z0-9_]{{3,}})@{}$",
Settings::get().hostname Settings::get().hostname
)) ))
.expect("compile webfinger regex") .expect("compile webfinger regex")