Skip to content

Commit

Permalink
Case-insensitive webfinger response. Fixes #1955 & #1986 (#2005)
Browse files Browse the repository at this point in the history
* Make webfinger case insensitive

* Make webfinger case insensitive

* Case insensitive domain name

* Case-insensitive webfinger

* formatting

Co-authored-by: Kradyz <k@radiz.nl>
  • Loading branch information
Kradyz and Kradyz committed Dec 20, 2021
1 parent c883a49 commit 9f64872
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api_tests/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions crates/db_schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion crates/db_schema/src/impls/community.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
functions::lower,
naive_now,
newtypes::{CommunityId, DbUrl, PersonId},
source::community::{
Expand Down Expand Up @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion crates/db_schema/src/impls/person.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
functions::lower,
naive_now,
newtypes::{DbUrl, PersonId},
schema::person::dsl::*,
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 2 additions & 0 deletions crates/db_schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion crates/utils/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 9f64872

Please sign in to comment.