Skip to content

Mapping pass doesn't work with DOS line endings in PHP files. #899

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

Open
GavChap opened this issue Dec 5, 2019 · 5 comments
Open

Mapping pass doesn't work with DOS line endings in PHP files. #899

GavChap opened this issue Dec 5, 2019 · 5 comments
Labels

Comments

@GavChap
Copy link

GavChap commented Dec 5, 2019

The mapping pass failes at the namespace generation point when you have DOS line endings in the PHP files.

For instance
^ "App\Security\Authenticator"
^ "/var/www/html/src"
^ "\OtherAuthenticator"
^ "/var/www/html/src"

Where Authenticator had Linux line endings (/n) and OtherAuthenticator in the same namespace as Authenticator had DOS line endings (/r/n)

@Emirii
Copy link

Emirii commented Jan 16, 2020

Thank you! I had many files with wrong line endings. Not sure if I should submit a PR but they should have something like this:

vendor\ongr\elasticsearch-bundle\DependencyInjection\Compiler\MappingPass.php: line 152

$namespaceLine = str_replace("\r\n", "\n", array_shift($lines));

to normalize both types of line endings so regex works. For some reason PHP regex recognizes this ;\n$ as match and not ;\r\n$ at the end of the regex.

In addition I had to only specify the folder I put my mapping files in so it doesn't scan the whole /src directory because it didn't like my DoctrineMigrations folder in there either.

ongr_elasticsearch:
    source_directories:
        - /src/ElasticsearchDocument

After those two tweaks I was finally able to get 6.x to work. I was stuck on 5.x for the longest time due to this, so thanks!

@saimaz
Copy link
Contributor

saimaz commented Jan 16, 2020

Well, I never have seen that any of the libraries (like doctrine, symfony etc) would check the line endings since it is the kind of responsibility of the user.

@saimaz
Copy link
Contributor

saimaz commented Jan 16, 2020

Also, files read doctrine cache reader component and not this library, so technically if you guys want to support file endings the issue should be opened in the doctrine ;)

@GavChap
Copy link
Author

GavChap commented Jan 16, 2020

Why not just remove the $ from the preg_match on line 160 and it should work no matter the line endings as you're not matching to end of line, only to the colon, so the $ is redundant.

preg_match('/^namespace (.*);$/', $namespaceLine, $match);

The real issue here is when you are working on your project in Windows and use Git to checkout to a linux dev server, Git will change the file endings to /r/n as you're checking it out on Windows, then you commit and push, it changes them back to /n, but while you're developing PHP is expecting the standard linux EOL.

@saimaz
Copy link
Contributor

saimaz commented Jan 17, 2020

I'll double-check if the removal of $ has no effect and if everything ok for sure will do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants