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

Error when the server script name is an absolute path #223

Closed
theofidry opened this issue Nov 11, 2023 · 4 comments · Fixed by #268
Closed

Error when the server script name is an absolute path #223

theofidry opened this issue Nov 11, 2023 · 4 comments · Fixed by #268
Assignees
Labels
bug Something isn't working

Comments

@theofidry
Copy link
Collaborator

With the current code:

$pwd = $_SERVER['PWD'];
        $scriptName = $_SERVER['SCRIPT_NAME'];

        return str_starts_with($scriptName, $pwd)
            ? $scriptName
            : $pwd.DIRECTORY_SEPARATOR.$scriptName;

If the script name is absolute, e.g. /usr/local/bin/box, the resolved script name will be a nonsensical path.

@theofidry theofidry self-assigned this Nov 11, 2023
@theofidry theofidry added the bug Something isn't working label Nov 11, 2023
@APochmann
Copy link
Contributor

I'm a pimcore user where this library is used e.g. to run the console commands for data-importer. Using that functionality I ran in exactly this issue with data import cron job which has absolute path for the script set.
For me, running a Linux server, the following change did solve the issue (will be different for e.g. Windows):

    private static function getScriptPath(): string
    {
        $pwd = $_SERVER['PWD'];
        $scriptName = $_SERVER['SCRIPT_NAME'];

        return (str_starts_with($scriptName, $pwd)
                || str_starts_with($scriptName, DIRECTORY_SEPARATOR))
            ? $scriptName
            : $pwd.DIRECTORY_SEPARATOR.$scriptName;
    }

@theofidry
Copy link
Collaborator Author

@APochmann would you be open to do a PR with this patch?

@APochmann
Copy link
Contributor

Sure, but I do not have possibility to test on Windows system, tested only on my Linux system

@theofidry
Copy link
Collaborator Author

That is ok, we don't own a windows machine either so this library has never really been tested on Windows. This could probably be done now by adding a Windows job to the pipeline since GA supports Windows, if someone wants to work on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants