microsoft / ALAppExtensions

Repository for collaboration on Microsoft AL application add-on and localization extensions for Microsoft Dynamics 365 Business Central.
MIT License
780 stars 617 forks source link

COD9520 - Mail management - ValidateEmailAddressField - Variable Length #3448

Closed BertDeTemmerman closed 5 years ago

BertDeTemmerman commented 5 years ago

Have an e-mail field in a table and call in the onvalidate ValidateEmailAddressField

field(50000; "E-Mail"; Text[80])
{
            ExtendedDatatype = EMail;
            trigger OnValidate()
            var
                MailManagement: Codeunit "Mail Management";
            begin
                MailManagement.ValidateEmailAddressField("E-Mail");
            end;
}

Codecop gives warning "Possible overflow assigning 'Text' to 'Text[80]'.AL(AA0139)" Cause ValidateEmailAddressField(VAR EmailAddress : Text) passes the field as var but as text

So shouldn't ValidateEmailAddressField pass this variable as text[80] instead of Text?

StanPesotskiy commented 5 years ago

We are limited in changing public function signatures. You can use a local text variable to pass validation:

var EMail: text;

EMail := "E-Mail";
MailManagement.ValidateEmailAddressField(EMail);
"E-Mail" := CopyStr(EMail,1,maxstrlen("E-Mail"));
BertDeTemmerman commented 5 years ago

Thank you for the answer and the workaround. But I will not do something such ridiculous for a simple codecop warning that's never going to be a problem ... I will just ignore the warning.