From 02a800e6cfae3f03552445fbc6daf7da10317756 Mon Sep 17 00:00:00 2001 From: Michael Brunton-Spall Date: Fri, 28 Jan 2022 17:10:39 +0000 Subject: [PATCH] Allow uppercase in emails This should fix #194 by allowing capital letters in the name portion of email addresses --- app/lib/email_validator.rb | 8 ++++---- test/lib/email_validator_test.rb | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/lib/email_validator.rb b/app/lib/email_validator.rb index c436642..e7c940d 100644 --- a/app/lib/email_validator.rb +++ b/app/lib/email_validator.rb @@ -19,10 +19,10 @@ def self.email_is_allowed_advanced?(email) # which domains are allowed to be requested for a gds-users account def self.allowed_emails_regexp /\A(#{Regexp.union( - /([a-z.\-\']+@digital\.cabinet-office\.gov\.uk,?\s*)/, - /([a-z.\-\']+@cabinetoffice\.gov\.uk,?\s*)/, - /([a-z.\-\']+@softwire\.com,?\s*)/, - /([a-z.\-\']+@fidusinfosec\.com,?\s*)/, + /([a-zA-Z.\-\']+@digital\.cabinet-office\.gov\.uk,?\s*)/, + /([a-zA-Z.\-\']+@cabinetoffice\.gov\.uk,?\s*)/, + /([a-zA-Z.\-\']+@softwire\.com,?\s*)/, + /([a-zA-Z.\-\']+@fidusinfosec\.com,?\s*)/, )})+\z/ end diff --git a/test/lib/email_validator_test.rb b/test/lib/email_validator_test.rb index 9452b5f..08061ec 100644 --- a/test/lib/email_validator_test.rb +++ b/test/lib/email_validator_test.rb @@ -79,6 +79,11 @@ class EmailValidatorTest < ActiveSupport::TestCase assert_match EmailValidator.allowed_emails_regexp, emails end + test 'Mixed case emails are matched by the allowed emails regexp' do + email = 'Test.User@cabinetoffice.gov.uk' + assert_match EmailValidator.allowed_emails_regexp, email + end + test 'Other email addresses should not match emails regexp' do email = 'fname.lname@example.com' assert_no_match EmailValidator.allowed_emails_regexp, email