Browse Source

Fix class names in comments being parsed in short_open_tags files, fixes #7289

Jordi Boggiano 6 years ago
parent
commit
3b9d6769bf

+ 4 - 0
src/Composer/Autoload/ClassMapGenerator.php

@@ -179,6 +179,10 @@ class ClassMapGenerator
         if (false !== $pos && false === strpos(substr($contents, $pos), '<?')) {
             $contents = substr($contents, 0, $pos);
         }
+        // strip comments if short open tags are in the file
+        if (preg_match('{(<\?)(?!(php|hh))}i', $contents)) {
+            $contents = preg_replace('{//.* | /\*(?:[^*]++|\*(?!/))*\*/}x', '', $contents);
+        }
 
         preg_match_all('{
             (?:

+ 0 - 8
tests/Composer/Test/Autoload/ClassMapGeneratorTest.php

@@ -62,14 +62,6 @@ class ClassMapGeneratorTest extends TestCase
             'ShortOpenTagDocblock' => realpath(__DIR__) . '/Fixtures/classmap/ShortOpenTagDocblock.php',
         );
 
-        /**
-         * @wontfix If short_open_tag is not enabled, we end up parsing the docblock because
-         *  php_strip_whitespace won't recognize the file. Funky edge-case (does not apply to HHVM).
-         */
-        if (!defined('HHVM_VERSION') && !ini_get('short_open_tag')) {
-            $classmap['description'] = realpath(__DIR__) . '/Fixtures/classmap/ShortOpenTagDocblock.php';
-        }
-
         $data = array(
             array(__DIR__ . '/Fixtures/Namespaced', array(
                 'Namespaced\\Bar' => realpath(__DIR__) . '/Fixtures/Namespaced/Bar.inc',

+ 1 - 0
tests/Composer/Test/Autoload/Fixtures/classmap/ShortOpenTagDocblock.php

@@ -2,4 +2,5 @@
 /**
  * Some class description here.
  */
+// other class name in comment
 class ShortOpenTagDocblock {}