Browse Source

ZF-9263, ZF-9166, ZF-9306: Fix open_basedir warnings on Windows

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22019 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 15 năm trước cách đây
mục cha
commit
71df8a89c9
2 tập tin đã thay đổi với 22 bổ sung0 xóa
  1. 8 0
      library/Zend/Loader.php
  2. 14 0
      tests/Zend/LoaderTest.php

+ 8 - 0
library/Zend/Loader.php

@@ -179,6 +179,14 @@ class Zend_Loader
             return true;
             return true;
         }
         }
 
 
+        if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN'
+            && preg_match('/^[a-z]:/i', $filename)
+        ) {
+            // If on windows, and path provided is clearly an absolute path, 
+            // return false immediately
+            return false;
+        }
+
         foreach (self::explodeIncludePath() as $path) {
         foreach (self::explodeIncludePath() as $path) {
             if ($path == '.') {
             if ($path == '.') {
                 if (is_readable($filename)) {
                 if (is_readable($filename)) {

+ 14 - 0
tests/Zend/LoaderTest.php

@@ -536,6 +536,20 @@ class Zend_LoaderTest extends PHPUnit_Framework_TestCase
     }
     }
 
 
     /**
     /**
+     * @group ZF-9263
+     * @group ZF-9166
+     * @group ZF-9306
+     */
+    public function testIsReadableShouldFailEarlyWhenProvidedInvalidWindowsAbsolutePath()
+    {
+        if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
+            $this->markTestSkipped('Windows-only test');
+        }
+        $path = 'C:/this/file/should/not/exist.php';
+        $this->assertFalse(Zend_Loader::isReadable($path));
+    }
+
+    /**
      * In order to play nice with spl_autoload, an autoload callback should
      * In order to play nice with spl_autoload, an autoload callback should
      * *not* emit errors (exceptions are okay). ZF-2923 requests that this
      * *not* emit errors (exceptions are okay). ZF-2923 requests that this
      * behavior be applied, which counters the previous request in ZF-2463.
      * behavior be applied, which counters the previous request in ZF-2463.