Light Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bug6451 email without top domain#6781

Open
Dan-Karlsson wants to merge 4 commits intomicrosoft:mainfrom
Dan-Karlsson:Bug6451-Email-Without-Top-Domain
Open

Bug6451 email without top domain#6781
Dan-Karlsson wants to merge 4 commits intomicrosoft:mainfrom
Dan-Karlsson:Bug6451-Email-Without-Top-Domain

Conversation

Copy link

Dan-Karlsson commented Feb 23, 2026 *
edited by github-actions bot
Loading

Summary

Validate email addresses to ensure they contain a top domain and that the top domain is at least 2 characters long

Work Item(s)

Fixes #6451

Dan-Karlsson requested a review from a team as a code owner February 23, 2026 19:34
github-actions bot added AL: System Application From Fork Pull request is coming from a fork labels Feb 23, 2026
duichwer suggested changes Feb 23, 2026
Copy link

duichwer left a comment

Choose a reason for hiding this comment

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

Could you add some tests with error assertions?

Copy link
Author

Dan-Karlsson commented Feb 23, 2026

Could you add some tests with error assertions?

I can't find any tests of those functions, so I'm not sure where to put them. And I'm also not sure how to write them to not risk failure with .Net-calls in different environments and similar.

Dan-Karlsson requested a review from duichwer February 23, 2026 21:48
Copy link

duichwer commented Feb 24, 2026

Could you add some tests with error assertions?

I can't find any tests of those functions, so I'm not sure where to put them. And I'm also not sure how to write them to not risk failure with .Net-calls in different environments and similar.

@Dan-Karlsson I think you're correct.
I couldn't find any tests for the mail validation in the system application tests either.
That doesn't mean that we shouldn't have there some tests.

There are some tests in the Base Application for the procedure CheckValidEmailAddress of codeunit "Mail Management"
https://github.com/microsoft/BusinessCentralApps/blob/main/App/Layers/W1/Tests/Integration-Internal/MailManagementTest.Codeunit.al
The procedure CheckValidEmailAddress internall calls the procedure of the email account codeunit

'); // Check that only one address is validated. if EmailAddress.Split('@').Count() <> 2 then Error(InvalidEmailAddressErr, EmailAddress); if not EmailAccount.ValidateEmailAddress(EmailAddress) then Error(InvalidEmailAddressErr, EmailAddress); end;"> [TryFunction]
procedure CheckValidEmailAddress(EmailAddress: Text)
var
EmailAccount: Codeunit "Email Account";
IsHandled: Boolean;
begin
IsHandled := false;
OnBeforeCheckValidEmailAddr(EmailAddress, IsHandled);
if IsHandled then
exit;

EmailAddress := DelChr(EmailAddress, '<>');

// Check that only one address is validated.
if EmailAddress.Split('@').Count() <> 2 then
Error(InvalidEmailAddressErr, EmailAddress);

if not EmailAccount.ValidateEmailAddress(EmailAddress) then
Error(InvalidEmailAddressErr, EmailAddress);
end;

Therefore I would suggest to some tests to https://github.com/microsoft/BCApps/blob/main/src/System%20Application/Test/Email/src/EmailAccountsTest.Codeunit.al.

duichwer suggested changes Feb 24, 2026
Copy link
Author

Dan-Karlsson commented Feb 24, 2026

@Dan-Karlsson I think you're correct. I couldn't find any tests for the mail validation in the system application tests either. That doesn't mean that we shouldn't have there some tests.

There are some tests in the Base Application for the procedure CheckValidEmailAddress of codeunit "Mail Management" https://github.com/microsoft/BusinessCentralApps/blob/main/App/Layers/W1/Tests/Integration-Internal/MailManagementTest.Codeunit.al The procedure CheckValidEmailAddress internall calls the procedure of the email account codeunit

Therefore I would suggest to some tests to https://github.com/microsoft/BCApps/blob/main/src/System%20Application/Test/Email/src/EmailAccountsTest.Codeunit.al.

Thank you! I didn't think to check in Base Application.

But I think the tests should be in Base Application, with added tests in the procedure TestInvalidEmailAddress. It's bad design to test some cases there and some other cases in a completely different part of the code.

procedure TestInvalidEmailAddress()
var
MailManagement: Codeunit "Mail Management";
begin
asserterror MailManagement.CheckValidEmailAddress('@a');
asserterror MailManagement.CheckValidEmailAddress('b@');
asserterror MailManagement.CheckValidEmailAddress('ab)@c.d');
asserterror MailManagement.CheckValidEmailAddress('a@@b');
end;

But I don't know how to add it there (without creating a new bug report in Base and a separate pull request for the tests, that won't work until this is approved).

JesperSchulz added the Integration GitHub request for Integration area label Feb 25, 2026
Aleyenda assigned darjoo Feb 27, 2026
Copy link
Contributor

darjoo commented Mar 2, 2026

You can put the tests in https://github.com/microsoft/BCApps/blob/main/src/System%20Application/Test/Email/src/EmailAccountsTest.Codeunit.al.

I've tested the change myself and it works. Once the tests are in, I'll approve the PR.

Copy link
Author

Dan-Karlsson commented Mar 2, 2026

You can put the tests in https://github.com/microsoft/BCApps/blob/main/src/System%20Application/Test/Email/src/EmailAccountsTest.Codeunit.al.

I've tested the change myself and it works. Once the tests are in, I'll approve the PR.

Thank you!

I have added tests now.

But I still think they should be merged with the tests in https://github.com/microsoft/BusinessCentralApps/blob/main/App/Layers/W1/Tests/Integration-Internal/MailManagementTest.Codeunit.al

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

duichwer duichwer requested changes

Reviewers whose approvals may not affect merge requirements

At least 2 approving reviews are required to merge this pull request.

Assignees

darjoo

Labels

AL: System Application From Fork Pull request is coming from a fork Integration GitHub request for Integration area

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Bug]: Email Address Without Top Domain is Validated

4 participants