sitegeist / Sitegeist.Archaeopteryx

The missing link editor for Neos
MIT License
21 stars 11 forks source link

BUGFIX: Do not fail on empty dimension values #68

Open gradinarufelix opened 1 month ago

gradinarufelix commented 1 month ago

Fixes #66. I disabled the check in the query DTOs and fall back to an empty array.

The reason the parameter is entirely missing and not just an empty array is found here:

for (const [dimensionName, fallbackChain] of Object.entries(
        query.dimensionValues
    )) {
        for (const fallbackValue of fallbackChain) {
            searchParams.set(
                `dimensionValues[${dimensionName}][]`,
                fallbackValue
            );
        }
    }

If query.dimensionValues is empty, there is no search parameter added.

Another solution would be to improve the client-side passing of the parameter by passing an actually empty array and keep the PHP checks instead.

Benjamin-K commented 1 month ago

I think the check should still be there, but should ignore a missing value. So either

$array['dimensionValues'] ??= [];

at the beginning of the function

or

if (isset($array['dimensionValues']) && !is_array($array['dimensionValues'])) {
    throw new \InvalidArgumentException('Dimension values must be an array');
}

should be added.

nezaniel commented 3 weeks ago

I'd definitively opt for the client-side solution

Benjamin-K commented 3 weeks ago

I'd still keep the client side solution. But the backend should still check for valid parameters, too.

nezaniel commented 3 weeks ago

Yes, that's what I mean (I guess ^^). The backend code should stay as it is and the client must send a valid dimension space point (even with empty coordinates) as an array