Upgrade to 3.5

This commit is contained in:
Bastian Allgeier
2020-12-15 11:01:41 +01:00
parent eabce32cf0
commit 9109130c9c
43 changed files with 306 additions and 159 deletions

View File

@@ -107,9 +107,10 @@ class FileCache extends Cache
*/
public function retrieve(string $key)
{
$file = $this->file($key);
$file = $this->file($key);
$value = F::read($file);
return Value::fromJson(F::read($file));
return $value ? Value::fromJson($value) : null;
}
/**

View File

@@ -76,8 +76,12 @@ class Blocks extends Items
return [];
}
// no layouts
if (array_key_exists('columns', $input[0]) === false) {
if (
// no columns = no layout
array_key_exists('columns', $input[0]) === false ||
// checks if this is a block for the builder plugin
array_key_exists('_key', $input[0]) === true
) {
return $input;
}

View File

@@ -202,15 +202,23 @@ class FileRules
* Validates the extension, MIME type and filename
*
* @param \Kirby\Cms\File $file
* @param string|null $mime If not passed, the MIME type is detected from the file
* @param string|null|false $mime If not passed, the MIME type is detected from the file,
* if `false`, the MIME type is not validated for performance reasons
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException If the extension, MIME type or filename is missing or forbidden
*/
public static function validFile(File $file, ?string $mime = null): bool
public static function validFile(File $file, $mime = null): bool
{
if ($mime === false) {
// request to skip the MIME check for performance reasons
$validMime = true;
} else {
$validMime = static::validMime($file, $mime ?? $file->mime());
}
return
$validMime &&
static::validExtension($file, $file->extension()) &&
static::validMime($file, $mime ?? $file->mime()) &&
static::validFilename($file, $file->filename());
}

View File

@@ -71,7 +71,7 @@ class Media
public static function publish(File $file, string $dest): bool
{
// never publish risky files (e.g. HTML, PHP or Apache config files)
FileRules::validFile($file);
FileRules::validFile($file, false);
$src = $file->root();
$version = dirname($dest);

View File

@@ -291,9 +291,9 @@ trait UserActions
/**
* Reads the user password from disk
*
* @return string|null
* @return string|false
*/
protected function readPassword(): ?string
protected function readPassword()
{
return F::read($this->root() . '/.htpasswd');
}

View File

@@ -44,11 +44,12 @@ abstract class Handler
*/
public static function read(string $file): array
{
if (is_file($file) !== true) {
$contents = F::read($file);
if ($contents === false) {
throw new Exception('The file "' . $file . '" does not exist');
}
return static::decode(F::read($file));
return static::decode($contents);
}
/**

View File

@@ -547,14 +547,19 @@ class F
}
/**
* Reads the content of a file
* Reads the content of a file or requests the
* contents of a remote HTTP or HTTPS URL
*
* @param string $file The path for the file
* @param string $file The path for the file or an absolute URL
* @return string|false
*/
public static function read(string $file)
{
if (is_file($file) !== true) {
if (
is_file($file) !== true &&
Str::startsWith($file, 'https://') !== true &&
Str::startsWith($file, 'http://') !== true
) {
return false;
}

View File

@@ -232,7 +232,7 @@ class File
/**
* Reads the file content and returns it.
*
* @return string
* @return string|false
*/
public function read()
{