Bugzilla – Attachment 187917 Details for
Bug 41025
Koha::Email->is_valid needs more attention
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 41025: Check for a dot in domain name, allow localhost
Bug-41025-Check-for-a-dot-in-domain-name-allow-loc.patch (text/plain), 2.66 KB, created by
Marcel de Rooy
on 2025-10-15 15:09:55 UTC
(
hide
)
Description:
Bug 41025: Check for a dot in domain name, allow localhost
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2025-10-15 15:09:55 UTC
Size:
2.66 KB
patch
obsolete
>From 78b4e241af098394de69f12ebddeea3afe07e660 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 15 Oct 2025 16:52:26 +0200 >Subject: [PATCH] Bug 41025: Check for a dot in domain name, allow localhost >Content-Type: text/plain; charset=utf-8 > >If Email::Address has been patched, this can be removed. > >Test plan: >Run t/Koha/Email.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/Email.pm | 9 ++++++++- > t/Koha/Email.t | 13 ++++++++----- > 2 files changed, 16 insertions(+), 6 deletions(-) > >diff --git a/Koha/Email.pm b/Koha/Email.pm >index ccb03ee070..7e7add1f2a 100644 >--- a/Koha/Email.pm >+++ b/Koha/Email.pm >@@ -245,8 +245,15 @@ Return true is the email address passed in parameter is valid following RFC 2822 > > sub is_valid { > my ( $class, $email ) = @_; >- my @addrs = Email::Address->parse($email); >+ my @addrs = _temporary_host_test( Email::Address->parse($email) ); > return @addrs ? 1 : 0; > } > >+sub _temporary_host_test { >+ >+ # regex looks for a dot in the domain, other case should be caught by E::A >+ # exception for localhost (see bug 28017 and Email.t) >+ return grep { $_->host =~ /\.|^localhost$/ } @_; >+} >+ > 1; >diff --git a/t/Koha/Email.t b/t/Koha/Email.t >index 0b73edeabd..c3cc27d998 100755 >--- a/t/Koha/Email.t >+++ b/t/Koha/Email.t >@@ -269,18 +269,21 @@ subtest 'send_or_die() tests' => sub { > }; > > subtest 'is_valid' => sub { >- plan tests => 8; >+ plan tests => 11; > > is( Koha::Email->is_valid('Fróm <from@example.com>'), 1 ); > is( Koha::Email->is_valid('from@example.com'), 1 ); > is( Koha::Email->is_valid('<from@example.com>'), 1 ); >- is( Koha::Email->is_valid('root@localhost'), 1 ); # See bug 28017 >+ is( Koha::Email->is_valid('root@localhost'), 1, 'localhost allowed as exception' ); # See bug 28017 >+ is( Koha::Email->is_valid('root@example.com.'), 1, 'trailing period got accepted, dont ask me why' ); > > is( Koha::Email->is_valid('<from@fróm.com>'), 0 ) > ; # "In accordance with RFC 822 and its descendants, this module demands that email addresses be ASCII only" >- isnt( Koha::Email->is_valid('@example.com'), 1 ); >- isnt( Koha::Email->is_valid('example.com'), 1 ); >- isnt( Koha::Email->is_valid('from'), 1 ); >+ isnt( Koha::Email->is_valid('@example.com'), 1 ); >+ isnt( Koha::Email->is_valid('example.com'), 1 ); >+ isnt( Koha::Email->is_valid('from'), 1 ); >+ isnt( Koha::Email->is_valid('root@example'), 1, 'example is not a TLD' ); >+ isnt( Koha::Email->is_valid('root@.example.com'), 1, 'period in front of domain' ); > }; > > subtest 'new_from_string() tests' => sub { >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 41025
:
187917