From 16fa0b0330e0a1481a60a8d2f9a57b128357a803 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 16 Apr 2024 17:24:33 +0200 Subject: [PATCH] :sparkles: Improve email clean mechanism --- backend/src/app/rpc/commands/profile.clj | 4 ++++ backend/test/backend_tests/rpc_profile_test.clj | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/backend/src/app/rpc/commands/profile.clj b/backend/src/app/rpc/commands/profile.clj index 89a50b6ad3..fe33da10dc 100644 --- a/backend/src/app/rpc/commands/profile.clj +++ b/backend/src/app/rpc/commands/profile.clj @@ -46,6 +46,10 @@ (let [email (str/lower email) email (if (str/starts-with? email "mailto:") (subs email 7) + email) + email (if (or (str/starts-with? email "<") + (str/ends-with? email ">")) + (str/trim email "<>") email)] email)) diff --git a/backend/test/backend_tests/rpc_profile_test.clj b/backend/test/backend_tests/rpc_profile_test.clj index cbaff60380..00d2f2ac0d 100644 --- a/backend/test/backend_tests/rpc_profile_test.clj +++ b/backend/test/backend_tests/rpc_profile_test.clj @@ -27,6 +27,14 @@ (t/use-fixtures :once th/state-init) (t/use-fixtures :each th/database-reset) + +(t/deftest clean-email + (t/is "foo@example.com" (profile/clean-email "mailto:foo@example.com")) + (t/is "foo@example.com" (profile/clean-email "mailto:")) + (t/is "foo@example.com" (profile/clean-email "")) + (t/is "foo@example.com" (profile/clean-email "foo@example.com>")) + (t/is "foo@example.com" (profile/clean-email "