microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
732 stars 243 forks source link

TextBuilder.ToText(int, int) crashes session if text is too short #5954

Closed mjmatthiesen closed 4 years ago

mjmatthiesen commented 4 years ago

Describe the bug If count (second int) is greater than the length, BC will crash

To Reproduce Steps and to reproduce the behaviour:

  1. Create the below extension and then run the action
pageextension 50100 CustomerListExt extends "Customer List"
{
    actions
    {
        addfirst(processing)
        {
            action(MyAction)
            {
                ApplicationArea = All;
                Caption = 'TextBuilder';
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                PromotedOnly = true;
                ToolTip = 'No thanks';

                trigger OnAction()
                var
                    tb: TextBuilder;
                    t: Text;
                begin
                    tb.Append('one two three');
                    tb.Replace('one', 'hundred');
                    t := tb.ToText(1, 20);
                    Message(t);
                end;
            }
        }
    }

Expected behavior Don't crash. Return the string up to count characters.

Screenshots image

5. Versions:

dzzzb commented 4 years ago

Don't crash. Return the string up to count characters.

Or at least, if this is really meant to be an error, catch it and make it a BC Error() type, not an unhandled exception.

mjmatthiesen commented 4 years ago

Don't crash. Return the string up to count characters.

Or at least, if this is really meant to be an error, catch it and make it a BC Error() type, not an unhandled exception.

Yes, should be a true error, but it can't be caught since the return type is already text. It's essentially just forwarding the problem from DotNet:

Exceptions The sum of startIndex and length is greater than the length of the current instance.

I resolved this in my code pretty readily, but I would like to see the base solution handle this better. These kind of errors can be pretty show stopping if they slip through testing.

atoader commented 4 years ago

Hi! Please take a minute to read the guidelines for this repository https://github.com/microsoft/AL and our collection of frequently asked questions https://github.com/Microsoft/AL/wiki/frequently-Asked-Questions .

As this repository is only for issues related to the AL compiler in latest developer preview environment for Dynamics 365 Business Central. We suggest that you open a support case or file a bug in Collaborate, to ensure that all Business Central users benefit from your catch as soon as possible.

To open a support case, you can:

If you file the bug in Collaborate, remember to include steps to reproduce the issue, and the Business Central build number and country version you're using.