From 786f416f2ef31726b9e6fa0a5edde36aecddf085 Mon Sep 17 00:00:00 2001 From: SOFe Date: Tue, 19 May 2020 17:34:51 +0800 Subject: [PATCH] Improved support for paths with backslashes on Unix filesystems (#3501) Fixes #3497 --- src/pocketmine/plugin/PluginBase.php | 6 +++--- src/pocketmine/utils/Utils.php | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/plugin/PluginBase.php b/src/pocketmine/plugin/PluginBase.php index aac4a891e..08ecd936e 100644 --- a/src/pocketmine/plugin/PluginBase.php +++ b/src/pocketmine/plugin/PluginBase.php @@ -78,8 +78,8 @@ abstract class PluginBase implements Plugin{ $this->loader = $loader; $this->server = $server; $this->description = $description; - $this->dataFolder = rtrim($dataFolder, "\\/") . "/"; - $this->file = rtrim($file, "\\/") . "/"; + $this->dataFolder = rtrim($dataFolder, "/" . DIRECTORY_SEPARATOR) . "/"; + $this->file = rtrim($file, "/" . DIRECTORY_SEPARATOR) . "/"; $this->configFile = $this->dataFolder . "config.yml"; $this->logger = new PluginLogger($this); $this->scheduler = new TaskScheduler($this->logger, $this->getFullName()); @@ -169,7 +169,7 @@ abstract class PluginBase implements Plugin{ * @return null|resource Resource data, or null */ public function getResource(string $filename){ - $filename = rtrim(str_replace("\\", "/", $filename), "/"); + $filename = rtrim(str_replace(DIRECTORY_SEPARATOR, "/", $filename), "/"); if(file_exists($this->file . "resources/" . $filename)){ return fopen($this->file . "resources/" . $filename, "rb"); } diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index c46850250..a6bb9c2d9 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -89,6 +89,7 @@ use function substr; use function sys_get_temp_dir; use function trim; use function xdebug_get_function_stack; +use const DIRECTORY_SEPARATOR; use const PHP_EOL; use const PHP_INT_MAX; use const PHP_INT_SIZE; @@ -639,7 +640,7 @@ class Utils{ * @return string */ public static function cleanPath($path){ - $result = str_replace(["\\", ".php", "phar://"], ["/", "", ""], $path); + $result = str_replace([DIRECTORY_SEPARATOR, ".php", "phar://"], ["/", "", ""], $path); //remove relative paths //TODO: make these paths dynamic so they can be unit-tested against @@ -648,7 +649,7 @@ class Utils{ \pocketmine\PATH => "" ]; foreach($cleanPaths as $cleanPath => $replacement){ - $cleanPath = rtrim(str_replace(["\\", "phar://"], ["/", ""], $cleanPath), "/"); + $cleanPath = rtrim(str_replace([DIRECTORY_SEPARATOR, "phar://"], ["/", ""], $cleanPath), "/"); if(strpos($result, $cleanPath) === 0){ $result = ltrim(str_replace($cleanPath, $replacement, $result), "/"); }