소스 검색

Handle files with no php at all, fixes #2910

Jordi Boggiano 11 년 전
부모
커밋
49d4054e51
2개의 변경된 파일15개의 추가작업 그리고 1개의 파일을 삭제
  1. 4 1
      src/Composer/Autoload/ClassMapGenerator.php
  2. 11 0
      tests/Composer/Test/Autoload/Fixtures/template/notphp.inc

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

@@ -124,7 +124,10 @@ class ClassMapGenerator
         $contents = preg_replace('{"[^"\\\\]*(\\\\.[^"\\\\]*)*"|\'[^\'\\\\]*(\\\\.[^\'\\\\]*)*\'}s', 'null', $contents);
         // strip leading non-php code if needed
         if (substr($contents, 0, 2) !== '<?') {
-            $contents = preg_replace('{^.+?<\?}s', '<?', $contents);
+            $contents = preg_replace('{^.+?<\?}s', '<?', $contents, 1, $replacements);
+            if ($replacements === 0) {
+                return array();
+            }
         }
         // strip non-php blocks in the file
         $contents = preg_replace('{\?>.+<\?}s', '?><?', $contents);

+ 11 - 0
tests/Composer/Test/Autoload/Fixtures/template/notphp.inc

@@ -0,0 +1,11 @@
+/**
+ * AJAX interface for remembering user preferences set on the fly
+ *
+ * Match /preferences/ajax/
+ */
+'preferences_ajax' => array
+(
+    'handler' => array ('midgard_admin_asgard_handler_preferences', 'ajax'),
+    'fixed_args' => array('preferences', 'ajax'),
+    'variable_args' => 0,
+),