fix: underscored users not searchable (#6362)

This commit is contained in:
Calum H.
2026-06-11 20:27:28 +01:00
committed by GitHub
parent e5831d38eb
commit c082594825
3 changed files with 25 additions and 4 deletions
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT id, username, avatar_url\n FROM users\n WHERE LOWER(username) LIKE $1 ESCAPE ''\n ORDER BY LOWER(username) = $2 DESC, LOWER(username), username\n LIMIT 25\n ",
"query": "\n SELECT id, username, avatar_url\n FROM users\n WHERE LOWER(username) LIKE $1 ESCAPE '\\'\n ORDER BY LOWER(username) = $2 DESC, LOWER(username), username\n LIMIT 25\n ",
"describe": {
"columns": [
{
@@ -31,5 +31,5 @@
true
]
},
"hash": "8d0ae0da359ebd33801f2796c841b9b3cc1a59f7cdee756ac5ce1c459e69a531"
"hash": "d0cabd1c74fa04c77a02e99e201e3f3c54b41e9f606db1f18accee33afdddf49"
}
@@ -286,13 +286,13 @@ impl DBUser {
let escaped_query = format!("{}%", escape_like(&lowercase_query));
let users = sqlx::query!(
"
r#"
SELECT id, username, avatar_url
FROM users
WHERE LOWER(username) LIKE $1 ESCAPE '\'
ORDER BY LOWER(username) = $2 DESC, LOWER(username), username
LIMIT 25
",
"#,
escaped_query,
lowercase_query
)
+21
View File
@@ -79,6 +79,16 @@ pub async fn search_users_escapes_wildcards_and_limits_results() {
.unwrap();
}
sqlx::query(
"
INSERT INTO users (id, username, email, role)
VALUES (2100, 'prefix_under_score', 'prefix_under_score@modrinth.com', 'developer')
",
)
.execute(&*test_env.db.pool)
.await
.unwrap();
let req = test::TestRequest::get()
.uri("/v3/users/search?query=prefix")
.to_request();
@@ -104,6 +114,17 @@ pub async fn search_users_escapes_wildcards_and_limits_results() {
test::read_body_json(resp).await;
assert!(users.is_empty());
let req = test::TestRequest::get()
.uri("/v3/users/search?query=prefix_")
.to_request();
let resp = test_env.call(req).await;
assert_status!(&resp, actix_http::StatusCode::OK);
let users: Vec<serde_json::Value> =
test::read_body_json(resp).await;
assert_eq!(users.len(), 1);
assert_eq!(users[0]["username"], "prefix_under_score");
let req = test::TestRequest::get()
.uri("/v3/users/search?query=%20%20")
.to_request();