Skip to content

Conversation

@rosalieper
Copy link
Contributor

Bug: T415017

@rosalieper rosalieper changed the title Add case insensitiviti to email search + test cases Add case insensitivity to email search + test cases Jan 22, 2026
SELECT 1
FROM {$dbName}.{$table}
WHERE user_email = :email
WHERE LOWER(CONVERT(user_email USING utf8mb4)) = LOWER(:email)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks interesting, and it's not immediately obvious to me why it is needed. Can we add a comment above this line to explain it?

Copy link
Contributor

@deer-wmde deer-wmde Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the table schema, the datatype of the user_email field is tinyblob, so I guess it makes sense (or is maybe even necessary) for the comparison: https://github.com/wbstack/api/blob/main/database/mw/new/mw1.43-wbs2.sql#L1005

edit:

gave it a quick test:

MariaDB root@localhost:mwdb_8127892d75> SELECT user_email FROM mwt_022411e763_user WHERE LOWER(CONVERT(user_email USING utf8mb4)) = LOWER('DENA@DENA.DENA') \G
***************************[ 1. row ]***************************
user_email | Dena@DENA.dena

1 row in set
Time: 0.002s

MariaDB root@localhost:mwdb_8127892d75> SELECT user_email FROM mwt_022411e763_user WHERE LOWER(user_email) = LOWER('DENA@DENA.DENA') \G
0 rows in set
Time: 0.002s

}

public function scopeWhereEmailInsensitive($query, string $email) {
return $query->whereRaw('LOWER(email) = ?', [strtolower($email)]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required? Looking at the quick test I did the case-insensitive searching worked for the Platform API users table. I believe this is because the email column uses the utf8mb4_unicode_ci collation. The ci stands for case-insensitive.

We should still keep the tests that prove that case-insensitive search works, though.

P.S. an FYI for the future, strtolower() only converts ASCII alphabetic characters. mb_strtolower() is needed to convert non-ASCII character as well.


class CheckUserEmailExistTest extends TestCase {
protected function tearDown(): void {
User::query()->delete();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
User::query()->delete();
// delete all users
User::query()->delete();

@deer-wmde
Copy link
Contributor

can confirm case-insensitive search works in the current state:

0 12:18 » deer@wmde-102295 ~/wbaas/wbaas-deploy (main *)
 $ k exec -ti deployments/api-queue-default -- php artisan wbs-user:check-email TEST@test.com
FOUND: TEST@test.com in apidb.users
FOUND: TEST@test.com in mwdb_bfb51d26a3.mwt_7693b27217_user
-------------------------------------------------
0 12:18 » deer@wmde-102295 ~/wbaas/wbaas-deploy (main *)
 $ k exec -ti deployments/api-queue-default -- php artisan wbs-user:check-email test@test.com
FOUND: test@test.com in apidb.users
FOUND: test@test.com in mwdb_bfb51d26a3.mwt_7693b27217_user
-------------------------------------------------
0 12:18 » deer@wmde-102295 ~/wbaas/wbaas-deploy (main *)
 $ k exec -ti deployments/api-queue-default -- php artisan wbs-user:check-email test@TEST.com
FOUND: test@TEST.com in apidb.users
FOUND: test@TEST.com in mwdb_bfb51d26a3.mwt_7693b27217_user
-------------------------------------------------

As Ollie pointed out it would be nice to get the search result string in the output and not the input string, but I can see how this is a bit difficult here because it would need to happen in WikiUserEmailChecker.php

@outdooracorn
Copy link
Member

As Ollie pointed out it would be nice to get the search result string in the output and not the input string, but I can see how this is a bit difficult here because it would need to happen in WikiUserEmailChecker.php

I suggest we get the case-insensitive stuff merged now, so we can do this GDPR request done before the time runs out, and can think about improvements after. 🙂

@deer-wmde deer-wmde merged commit de75abb into main Jan 23, 2026
5 checks passed
@deer-wmde deer-wmde deleted the T415017 branch January 23, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants