Upgrade to 3.6.0

This commit is contained in:
Bastian Allgeier
2021-11-16 14:53:37 +01:00
parent 7388fa4d24
commit 92b7a330fa
318 changed files with 20017 additions and 6878 deletions

View File

@@ -16,24 +16,57 @@ use Kirby\Exception\InvalidArgumentException;
*/
class Svgz extends Svg
{
/**
* Sanitizes the given string
*
* @param string $string
* @return string
*
* @throws \Kirby\Exception\InvalidArgumentException If the file couldn't be parsed or recompressed
*/
public static function sanitize(string $string): string
{
$string = static::uncompress($string);
$string = parent::sanitize($string);
$string = @gzencode($string);
if (is_string($string) !== true) {
throw new InvalidArgumentException('Could not recompress gzip data'); // @codeCoverageIgnore
}
return $string;
}
/**
* Validates file contents
*
* @param string $string
* @return void
*
* @throws \Kirby\Exception\InvalidArgumentException If the file couldn't be parsed
* @throws \Kirby\Exception\InvalidArgumentException If the file didn't pass validation
*/
public static function validate(string $string): void
{
parent::validate(static::uncompress($string));
}
/**
* Uncompresses the SVGZ data
*
* @param string $string
* @return string
*/
protected static function uncompress(string $string): string
{
// only support uncompressed files up to 10 MB to
// prevent gzip bombs from crashing the process
$uncompressed = @gzdecode($string, 10000000);
$string = @gzdecode($string, 10000000);
if (is_string($uncompressed) !== true) {
if (is_string($string) !== true) {
throw new InvalidArgumentException('Could not uncompress gzip data');
}
parent::validate($uncompressed);
return $string;
}
}