Fix path handling on Windows

Fixes #307; thank you @bpgs for reporting!
This commit is contained in:
Daniel Rudolf 2015-12-23 16:17:06 +01:00
parent 14e5f3236c
commit 5be2f8e597
3 changed files with 13 additions and 6 deletions

View File

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

View File

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

View File

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