diff --git a/src/plugin/DiskResourceProvider.php b/src/plugin/DiskResourceProvider.php index 3ef8e6d66..33d62b18c 100644 --- a/src/plugin/DiskResourceProvider.php +++ b/src/plugin/DiskResourceProvider.php @@ -53,7 +53,7 @@ class DiskResourceProvider implements ResourceProvider{ * @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 . $filename)){ $resource = fopen($this->file . $filename, "rb"); if($resource === false) throw new AssumptionFailedError("fopen() should not fail on a file which exists"); diff --git a/src/plugin/PluginBase.php b/src/plugin/PluginBase.php index 8f5c0d3b8..56febce91 100644 --- a/src/plugin/PluginBase.php +++ b/src/plugin/PluginBase.php @@ -83,9 +83,9 @@ abstract class PluginBase implements Plugin, CommandExecutor{ $this->loader = $loader; $this->server = $server; $this->description = $description; - $this->dataFolder = rtrim($dataFolder, "\\/") . "/"; + $this->dataFolder = rtrim($dataFolder, "/" . DIRECTORY_SEPARATOR) . "/"; //TODO: this is accessed externally via reflection, not unused - $this->file = rtrim($file, "\\/") . "/"; + $this->file = rtrim($file, "/" . DIRECTORY_SEPARATOR) . "/"; $this->configFile = $this->dataFolder . "config.yml"; $prefix = $this->getDescription()->getPrefix(); diff --git a/src/utils/Filesystem.php b/src/utils/Filesystem.php index ab60becaa..7709deb5f 100644 --- a/src/utils/Filesystem.php +++ b/src/utils/Filesystem.php @@ -42,6 +42,7 @@ use function str_replace; use function stream_get_contents; use function strpos; use function unlink; +use const DIRECTORY_SEPARATOR; use const LOCK_EX; use const LOCK_NB; use const LOCK_SH; @@ -80,7 +81,7 @@ final class Filesystem{ * @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 @@ -89,7 +90,7 @@ final class Filesystem{ \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), "/"); } diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 17d4b495d..7069f85cc 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -72,6 +72,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;