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

Missing trim() function causes error when running php 7.3 on WSL on Windows 10 #927

Open
pawellen opened this issue Mar 18, 2020 · 2 comments

Comments

@pawellen
Copy link

Hi,
When running in php 7.3 on WSL on Windows 10 preg_grep returns windows style line endings (\n\r) at the end of line string. To be precise in https://github.com/ongr-io/ElasticsearchBundle/blob/master/DependencyInjection/Compiler/MappingPass.php#L165
got this value:

array:1 [▼
2 => "namespace App\Admin\Common\Controller;\n\r"
]

this causes: _preg_match('/^namespace (.*);$/', $namespaceLine, $match); to fail because of 2 whitespace at end dont match $ i preg.

To fix this issue need to make sure that namespace does not have any whitesapces so in
https://github.com/ongr-io/ElasticsearchBundle/blob/master/DependencyInjection/Compiler/MappingPass.php#L166 please add trim:
$namespaceLine = trim(array_shift($lines));

Please help :)

@pawellen
Copy link
Author

Any update on that?

@pawellen
Copy link
Author

Required patch:

Index: vendor/ongr/elasticsearch-bundle/DependencyInjection/Compiler/MappingPass.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- vendor/ongr/elasticsearch-bundle/DependencyInjection/Compiler/MappingPass.php	(date 1584856142992)
+++ vendor/ongr/elasticsearch-bundle/DependencyInjection/Compiler/MappingPass.php	(date 1584856142992)
@@ -163,7 +163,7 @@
     private function getFullNamespace($filename)
     {
         $lines = preg_grep('/^namespace /', file($filename));
-        $namespaceLine = array_shift($lines);
+        $namespaceLine = trim(array_shift($lines));
         $match = array();
         preg_match('/^namespace (.*);$/', $namespaceLine, $match);
         $fullNamespace = array_pop($match);

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

No branches or pull requests

1 participant