diff --git a/CHANGELOG.md b/CHANGELOG.md index 0364e0d..5e2eb8f 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/lib/Pico.php b/lib/Pico.php index 112745a..4bf90fe 100644 --- a/lib/Pico.php +++ b/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, '/\\') . '/'; } /** diff --git a/plugins/00-PicoDeprecated.php b/plugins/00-PicoDeprecated.php index a9a272d..b3207cf 100644 --- a/plugins/00-PicoDeprecated.php +++ b/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;