Bläddra i källkod

Fix path handling on Windows

Fixes #307; thank you @bpgs for reporting!
Daniel Rudolf 9 år sedan
förälder
incheckning
5be2f8e597
3 ändrade filer med 13 tillägg och 6 borttagningar
  1. 1 0
      CHANGELOG.md
  2. 11 5
      lib/Pico.php
  3. 1 1
      plugins/00-PicoDeprecated.php

+ 1 - 0
CHANGELOG.md

@@ -15,6 +15,7 @@ Released: -
             with a title in the navigation
 * [Changed] #292: Ignore YAML parse errors (meta data) in `Pico::readPages()`
 * [Fixed] Support empty meta header
+* [Fixed] #307: Fix path handling on Windows
 ```
 
 ### Version 1.0.0-beta.2

+ 11 - 5
lib/Pico.php

@@ -213,7 +213,7 @@ class Pico
      */
     public function __construct($rootDir, $configDir, $pluginsDir, $themesDir)
     {
-        $this->rootDir = rtrim($rootDir, '/') . '/';
+        $this->rootDir = rtrim($rootDir, '/\\') . '/';
         $this->configDir = $this->getAbsolutePath($configDir);
         $this->pluginsDir = $this->getAbsolutePath($pluginsDir);
         $this->themesDir = $this->getAbsolutePath($themesDir);
@@ -1219,7 +1219,7 @@ class Pico
 
         $this->config['base_url'] =
             $protocol . "://" . $_SERVER['HTTP_HOST']
-            . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/') . '/';
+            . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\') . '/';
 
         return $this->getConfig('base_url');
     }
@@ -1323,10 +1323,16 @@ class Pico
      */
     public function getAbsolutePath($path)
     {
-        if (substr($path, 0, 1) !== '/') {
-            $path = $this->getRootDir() . $path;
+        if (strncasecmp(PHP_OS, 'WIN', 3) === 0) {
+            if (preg_match('/^([a-zA-Z]:\\\\|\\\\\\\\)/', $path) !== 1) {
+                $path = $this->getRootDir() . $path;
+            }
+        } else {
+            if (substr($path, 0, 1) !== '/') {
+                $path = $this->getRootDir() . $path;
+            }
         }
-        return rtrim($path, '/') . '/';
+        return rtrim($path, '/\\') . '/';
     }
 
     /**

+ 1 - 1
plugins/00-PicoDeprecated.php

@@ -175,7 +175,7 @@ class PicoDeprecated extends AbstractPicoPlugin
                     $config['base_url'] = rtrim($config['base_url'], '/') . '/';
                 }
                 if (isset($config['content_dir'])) {
-                    $config['content_dir'] = rtrim($config['content_dir'], '/') . '/';
+                    $config['content_dir'] = rtrim($config['content_dir'], '/\\') . '/';
                 }
 
                 $realConfig = $config + $realConfig;