From 1957e63ceb81b1ef6f65066f0971c4c502272293 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Tue, 13 Jan 2026 15:15:34 +0200 Subject: [PATCH] Bug 15349: Accept email addresses with display name in system preferences To test: 1. Before applying this patch, navigate to system preferences 2. Search for preference KohaAdminEmailAddress 3. Enter anything that is not in the format of valid "email@address.com" 4. Observe error "Please enter a valid email address." 5. Apply patch 6. Enter anything that is not in the format of valid "email@address.com" and not in the format of "display name " 7. Observe error "Please enter a valid email address (display name allowed)." 8. Enter email@address.com 9. Save all Administration preferences 10. Observe no errors 11. Enter Display Name 12. Save all Administration preferences 13. Observe no errors --- .../en/modules/admin/preferences/admin.pref | 2 +- .../prog/js/pages/preferences.js | 6 ++++++ .../intranet-tmpl/prog/js/staff-global.js | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref index eac9b14907b..51b13021728 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref @@ -4,7 +4,7 @@ Administration: - - "Email address for the administrator of Koha: " - pref: KohaAdminEmailAddress - class: email + class: email-with-display-name - "(This is the default From: address for emails unless there is one for the particular library, and is referred to when an internal error occurs.)" - - "Email address to be set as the replyto in emails: " diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js index bbe128f2491..2cf6419fcb6 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js @@ -371,6 +371,12 @@ $(".preference-email").each(function () { }); }); +$(".preference-email-with-display-name").each(function () { + $(this).rules("add", { + email_with_display_name: true, + }); +}); + $(".modalselect").on("click", function () { var datasource = $(this).data("source"); var exclusions = $(this).data("exclusions").split("|"); diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js index 3e8f312d274..e5b90de5ff4 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js +++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js @@ -188,6 +188,25 @@ $(document).ready(function () { decimal_rate: true, }); + jQuery.validator.addMethod( + "email_with_display_name", + function (value, element) { + // https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address + let html5_email_regex = + "[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*"; + let display_name_regex = "[^<>\x0A\x0D]+"; + let validation_regex = new RegExp( + `^${display_name_regex}<${html5_email_regex}>\$|^${html5_email_regex}\$` + ); + return this.optional(element) || validation_regex.test(value); + }, + __("Please enter a valid email address (display name allowed).") + ); + + jQuery.validator.addClassRules("email_with_display_name", { + email_with_display_name: true, + }); + $("#logout").on("click", function () { logOut(); }); -- 2.34.1