From 89ff24b4ac52c37ab3c4205277e335c061a6a887 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 2 Aug 2016 18:58:13 +0200 Subject: [PATCH] Fix calculation of paths during WCFSetup --- .../install/files/lib/system/WCFSetup.class.php | 4 ++-- .../PackageInstallationDispatcher.class.php | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index 6ebde3c0ee..9787bdc052 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -512,7 +512,7 @@ class WCFSetup extends WCF { } else { // resolve path relative to document root - $relativePath = str_replace(FileUtil::unifyDirSeparator($_SERVER['DOCUMENT_ROOT']), '', FileUtil::unifyDirSeparator(INSTALL_SCRIPT_DIR)); + $relativePath = FileUtil::getRelativePath($_SERVER['DOCUMENT_ROOT'], INSTALL_SCRIPT_DIR); foreach ($packages as $application => $packageData) { self::$directories[$application] = $relativePath . ($application === 'wcf' ? '' : $packageData['directory'] . '/'); } @@ -834,7 +834,7 @@ class WCFSetup extends WCF { } else { // regular file - $fileInserts[] = str_replace(WCF_DIR, '', $file); + $fileInserts[] = preg_replace('/^'.preg_quote(WCF_DIR, '/').'/', '', $file); } } diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php index 62dfd3336a..8dfbbdb181 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php @@ -794,8 +794,19 @@ class PackageInstallationDispatcher { $wcfDomainPath = $row['domainPath']; } - $documentRoot = str_replace($wcfDomainPath, '', FileUtil::unifyDirSeparator(WCF_DIR)); - $domainPath = str_replace($documentRoot, '', $packageDir); + $documentRoot = ''; + + // strip longest common suffix + $a = strrev(FileUtil::unifyDirSeparator($wcfDomainPath)); + $b = strrev($documentRoot = FileUtil::unifyDirSeparator(WCF_DIR)); + for ($i = 0, $max = min(strlen($a), strlen($b)); $i < $max; $i++) { + if ($a{$i} !== $b{$i}) { + $documentRoot = substr(strrev($b), 0, -$i); + break; + } + } + + $domainPath = FileUtil::addLeadingSlash(FileUtil::getRelativePath($documentRoot, $packageDir)); // update application path $application = new Application($this->getPackage()->packageID); -- 2.20.1