neos / neos-development-collection

The unified repository containing the Neos core packages, used for Neos development.
https://www.neos.io/
GNU General Public License v3.0
260 stars 221 forks source link

Bug `Neos.Fusion:Match` with `@default = ${null}` #3630

Open mhsdesign opened 2 years ago

mhsdesign commented 2 years ago

The MatchImplementation doesnt allow to use a default of the actual php null. It assumes it gets null because the fusion path was not found. Instead we would need to check the runtime last evaluation status.

https://github.com/neos/neos-development-collection/blob/2b27a1d372f7a54cfa847411bbdf1fc9936af45d/Neos.Fusion/Classes/FusionObjects/MatchImplementation.php#L47

steps to reproduce:

run:

root = Neos.Fusion:Match {
    @subject = ${'abc'}
    @default = ${null}
}

expect: null as result (eg. no result to see)

actual: Unhandled match Exception

More: Php 8 match allows a default of null, so we should allow it too.

Same also for matching paths like when 'abc' was defined but set to null, it would continue on to the default, as it thinks null was returned because the path is not defined.

When testing this, use an eel null instead of fusion null, as foo = null is omited while parsing

Neos since introduction of matcher

A super hacky idea: __eelExpression => "null"

mhsdesign commented 2 years ago

can be archived by using here:

https://github.com/neos/neos-development-collection/blob/master/Neos.Fusion/Classes/FusionObjects/MatchImplementation.php#L42-L44

this:

if ($result !== null || $this->runtime->getLastEvaluationStatus() !== Runtime::EVALUATION_SKIPPED) {
    return $result;
}

(same for @default)

mhsdesign commented 2 years ago

pinging @Sebobo as you created this ;)

would that be the correct handling?

Sebobo commented 2 years ago

You know more about this behaviour than me, if your change fixes the issue and all the tests are fine I'm happy with that 👍