Merge commit '786f416f2ef31726b9e6fa0a5edde36aecddf085'

# Conflicts:
#	resources/vanilla
#	src/plugin/PluginBase.php
#	src/utils/Utils.php
This commit is contained in:
Dylan K. Taylor 2020-05-19 21:19:44 +01:00
commit 5b7a55660f
4 changed files with 7 additions and 5 deletions

View File

@ -53,7 +53,7 @@ class DiskResourceProvider implements ResourceProvider{
* @return null|resource Resource data, or null * @return null|resource Resource data, or null
*/ */
public function getResource(string $filename){ public function getResource(string $filename){
$filename = rtrim(str_replace("\\", "/", $filename), "/"); $filename = rtrim(str_replace(DIRECTORY_SEPARATOR, "/", $filename), "/");
if(file_exists($this->file . $filename)){ if(file_exists($this->file . $filename)){
$resource = fopen($this->file . $filename, "rb"); $resource = fopen($this->file . $filename, "rb");
if($resource === false) throw new AssumptionFailedError("fopen() should not fail on a file which exists"); if($resource === false) throw new AssumptionFailedError("fopen() should not fail on a file which exists");

View File

@ -83,9 +83,9 @@ abstract class PluginBase implements Plugin, CommandExecutor{
$this->loader = $loader; $this->loader = $loader;
$this->server = $server; $this->server = $server;
$this->description = $description; $this->description = $description;
$this->dataFolder = rtrim($dataFolder, "\\/") . "/"; $this->dataFolder = rtrim($dataFolder, "/" . DIRECTORY_SEPARATOR) . "/";
//TODO: this is accessed externally via reflection, not unused //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"; $this->configFile = $this->dataFolder . "config.yml";
$prefix = $this->getDescription()->getPrefix(); $prefix = $this->getDescription()->getPrefix();

View File

@ -42,6 +42,7 @@ use function str_replace;
use function stream_get_contents; use function stream_get_contents;
use function strpos; use function strpos;
use function unlink; use function unlink;
use const DIRECTORY_SEPARATOR;
use const LOCK_EX; use const LOCK_EX;
use const LOCK_NB; use const LOCK_NB;
use const LOCK_SH; use const LOCK_SH;
@ -80,7 +81,7 @@ final class Filesystem{
* @return string * @return string
*/ */
public static function cleanPath($path){ public static function cleanPath($path){
$result = str_replace(["\\", ".php", "phar://"], ["/", "", ""], $path); $result = str_replace([DIRECTORY_SEPARATOR, ".php", "phar://"], ["/", "", ""], $path);
//remove relative paths //remove relative paths
//TODO: make these paths dynamic so they can be unit-tested against //TODO: make these paths dynamic so they can be unit-tested against
@ -89,7 +90,7 @@ final class Filesystem{
\pocketmine\PATH => "" \pocketmine\PATH => ""
]; ];
foreach($cleanPaths as $cleanPath => $replacement){ foreach($cleanPaths as $cleanPath => $replacement){
$cleanPath = rtrim(str_replace(["\\", "phar://"], ["/", ""], $cleanPath), "/"); $cleanPath = rtrim(str_replace([DIRECTORY_SEPARATOR, "phar://"], ["/", ""], $cleanPath), "/");
if(strpos($result, $cleanPath) === 0){ if(strpos($result, $cleanPath) === 0){
$result = ltrim(str_replace($cleanPath, $replacement, $result), "/"); $result = ltrim(str_replace($cleanPath, $replacement, $result), "/");
} }

View File

@ -72,6 +72,7 @@ use function substr;
use function sys_get_temp_dir; use function sys_get_temp_dir;
use function trim; use function trim;
use function xdebug_get_function_stack; use function xdebug_get_function_stack;
use const DIRECTORY_SEPARATOR;
use const PHP_EOL; use const PHP_EOL;
use const PHP_INT_MAX; use const PHP_INT_MAX;
use const PHP_INT_SIZE; use const PHP_INT_SIZE;