ElasticsearchBundle icon indicating copy to clipboard operation
ElasticsearchBundle copied to clipboard

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

Open pawellen opened this issue 4 years ago • 2 comments

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 avatar Mar 18 '20 19:03 pawellen

Any update on that?

pawellen avatar Sep 27 '20 15:09 pawellen

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);

pawellen avatar Sep 27 '20 15:09 pawellen