Skip to content

Generating under Windows does not compute relative path correctly #123

@jausions

Description

@jausions

Describe the bug

Under Windows, running the command to generate code includes a relative path to the configuration file that goes all the way to the root of the Windows drive. So instead of having something like that:

    public static function config(): string
    {
        return \Safe\realpath(__DIR__ . '/../../../../../sailor.php');
    }

We obtain something like the following:

    public static function config(): string
    {
        return \Safe\realpath(__DIR__ . '/../../../../../../C:\Users\johndoe\Documents\dev\project\website\sailor.php');
    }

Expected behavior/Solution

Regardless of operating system, we should get the short form of relative path.

Steps to reproduce

  1. Be under Windows
  2. Run the code generator

Output/Logs

Nothing of importance.

How to get around the issue

Change \Spawnia\Sailor\Codegen\Generator::configPath this way:

    protected function configPath(string $directory): string
    {
        // $from = explode('/', $directory);
        // $to = explode('/', $this->configFile);
        $from = preg_split('~[\\\\/]~', $directory);
        $to = preg_split('~[\\\\/]~', $this->configFile);

I am not having much time on my hand to do a PR. If nobody does, I'll see if I can get to it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error within Sailor

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions