Skip to content

Validator rule required-entry crashes when value is null #797

@amenk

Description

@amenk

Summary (*)

We upgraded to Magento 2.4.3 and cannot load the product editor anymore in the backend.

There is a javascript error raised:

Uncaught TypeError: Cannot read properties of null (reading 'padding')
    at Object.eval [as handler] (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:19:182)
    at validate (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:5:61)
    at eval (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:8:217)
    at Function._.every._.all (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:16:571)
    at validator (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:8:112)
    at UiClass.validate (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:9:678)
    at setNested (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:5:50)
    at Object.nested (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:11:127)
    at UiClass.set (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:12:318)
    at updateValue (eval at require.load (ffa15b10614cc201590659b91698e94c.min.js:178), <anonymous>:11:80)

We tracked that down to the following code

if (typeof value === 'object' && !!(value.padding || value.margin)) {

It seems to be a valid case, that value is null. In this case, the script still tried to read .padding.

Is that intended?

Also I do not understand why the validator required-entry is registered - isn't that already a commonly used validator which also should work on null values?

Proposed solution

if (typeof value === 'object' && value !== null && !!(value.padding || value.margin)) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions