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

[8.x] Make user policy command fix (Windows) #36445

Closed
wants to merge 1 commit into from

Conversation

zholzhas
Copy link
Contributor

@zholzhas zholzhas commented Mar 3, 2021

When trying to run php artisan make:policy UserPolicy --model=User on Windows, the created file will contain:

use App\Models\User;
use App\Models\User;

@derekmd
Copy link
Contributor

derekmd commented Mar 3, 2021

Many Windows devs have Git configured to checkout code using Unix "\n" newlines:

git config --global core.autocrlf false
git config --global core.eol lf

So this change would break that behaviour. i.e., on Windows the code is now trying to match \r\n but the downloaded "laravel/framework" stub is formatted with \n.

A wider fix would be a switch to using preg_replace() to match any newline characters:

return preg_replace(
    vsprintf('/use %s;[\r\n]+use %s;/', [
        preg_quote($namespacedModel, '/'),
        preg_quote($namespacedModel, '/'),
    ]),
    "use {$namespacedModel};",
    $stub
);

@taylorotwell
Copy link
Member

Feel free to resubmit with @derekmd's suggestion.

@zholzhas zholzhas deleted the make-policy-command branch March 4, 2021 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants