Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace with a path set to null crashes ajax calls #16513

Open
BobRay opened this issue Jan 17, 2024 · 0 comments
Open

Namespace with a path set to null crashes ajax calls #16513

BobRay opened this issue Jan 17, 2024 · 0 comments
Labels
bug The issue in the code or project, which should be addressed.

Comments

@BobRay
Copy link
Contributor

BobRay commented Jan 17, 2024

Bug report

Summary

This is very much an edge case.

The code below will fail in PHP >= 8.1 if the path is null. If the 'path' or 'assets_path' of a namespace are null, this throws a deprecation warning (no warning if the value is empty). If it happens in a processor and the deprecation warning is returned, the JS will crash because the warning it not valid JSON. I think this only happens with an empty cache, because then MODX re-creates the namespace cache on every request.

This error also shows up in page content when the cache is empty.

It does not occur if display_errors is off or E_DEPRECATED errors are not caught.

The two fields allow null to be set. Some extras that don't need an assets_path have it set to null. The only ones I know about are mine, but there may be others.

public static function translatePath(xPDO &$xpdo,$path) {
        return str_replace(array(
            '{core_path}',
            '{base_path}',
            '{assets_path}',
        ),array(
            $xpdo->getOption('core_path',null,MODX_CORE_PATH),
            $xpdo->getOption('base_path',null,MODX_BASE_PATH),
            $xpdo->getOption('assets_path',null,MODX_ASSETS_PATH),
        ),$path);
    }

The simplest way to solve it is to add this at the top of the function:

$path = $path===null? '' : $path;

It might also be a good idea to do that same conversion in modNamespace->save(), and if necessary, in the transport package code that saves the namespace (if it doesn't call the namespace's save() method).

Step to reproduce

Set a namespace assets_path value to null, turn on display_errors, with error reporting set to display E_DEPRECATED errors.

You can also see this by setting up test code with the translatePath() code above and calling:

translatePath($modx, null);

Observed behavior

error message

Expected behavior

No error message

@BobRay BobRay added the bug The issue in the code or project, which should be addressed. label Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue in the code or project, which should be addressed.
Projects
None yet
Development

No branches or pull requests

1 participant