umbraco / Umbraco.Forms.Issues

Public issue tracker for Umbraco Forms
29 stars 0 forks source link

A form can not be handled/opened when a prevalue is null (Forms 8) #1148

Closed wvankesteren-ax closed 8 months ago

wvankesteren-ax commented 8 months ago

A brief description of the issue goes here.

We have an Umbraco Forms v7.0.7 form that has been converted to Umbraco Forms v8.18.12 where a list of prevalues contains a null value. This prevents the form to be loaded correctly.

Reproduction

Since this is a converted form we have no easy steps to reproduce, however the fix could be very easy.

There will be a NPE on line 94 in function ParsePrevalueStoredWithSeparator() in field.cs (Umbraco.Forms.Core.Models.Field):

    private FieldPrevalue ParsePrevalueStoredWithSeparator(string prevalue)
    {
        if (prevalue.Contains("~|~")) // <-- NPE in case prevalue == null
        {
            string[] array = prevalue.Split(new string[1] { "~|~" }, StringSplitOptions.RemoveEmptyEntries);
            return new FieldPrevalue
            {
                Value = array[0],
                Caption = array[1]
            };
        }
        return new FieldPrevalue
        {
            Value = prevalue
        };
    }

this can easily fixed by changing this line into

        if (prevalue != null && prevalue.Contains("~|~"))

bottomline: a form should always be able to open in edit mode in order to correct it!

Since this customer project is Umbraco Forms v8, please port the fix to Umbraco Forms v8.

This is mandatory to serve your customers at the best!

f170b89e-7ef7-4df6-8825-0a8ee0b58719


This item has been added to our backlog AB#36739

AndyButland commented 8 months ago

I had a bit of trouble replicating the exception, as it seems if I just manipulate the database field containing the definition of a prevalue in a form to have a null value, the serialization from the stored definition fails. But in any case, I can certainly see that it would be useful to program more defensively here, so I've added this null check which will be included in the next patch release for Forms 8.

wvankesteren-ax commented 8 months ago

many thanx!