From dbcbd13aad86c2bf6faf34785716c8eb41a0e0d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=A0pa=C4=8Dek?= Date: Fri, 16 Feb 2024 22:54:30 +0100 Subject: [PATCH] Update nette/http to v3.2.4, not to 3.3.0 Because of https://github.com/nette/http/issues/233 --- site/composer.json | 2 +- site/composer.lock | 19 ++++---- site/vendor/composer/installed.json | 19 ++++---- site/vendor/composer/installed.php | 10 ++--- site/vendor/nette/http/composer.json | 5 ++- .../vendor/nette/http/src/Http/FileUpload.php | 39 +++++++++++++---- .../nette/http/src/Http/RequestFactory.php | 43 ++++++++++--------- site/vendor/nette/http/src/Http/Url.php | 2 +- 8 files changed, 87 insertions(+), 52 deletions(-) diff --git a/site/composer.json b/site/composer.json index 707f11b9c..b6157f7b2 100644 --- a/site/composer.json +++ b/site/composer.json @@ -25,7 +25,7 @@ "nette/database": "^3.1.5", "nette/di": "^3.1.8", "nette/forms": "^3.1.7", - "nette/http": "^3.1.6", + "nette/http": "3.2.4", "nette/mail": "^4.0", "nette/neon": "^3.3.3", "nette/security": "^3.1.8", diff --git a/site/composer.lock b/site/composer.lock index 3019b9e04..c9f359242 100644 --- a/site/composer.lock +++ b/site/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6f0d8c8d8bb243394d0e0de9650ce204", + "content-hash": "2d3af6517f9ee795fa03e2a3bc68a8d0", "packages": [ { "name": "contributte/translation", @@ -772,16 +772,16 @@ }, { "name": "nette/http", - "version": "v3.2.3", + "version": "v3.2.4", "source": { "type": "git", "url": "https://github.com/nette/http.git", - "reference": "54d79711ff3a8dfd86201e3bdbdd6972177ea20b" + "reference": "d7cc833ee186d5139cde5aab43b39ee7aedd6f22" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/http/zipball/54d79711ff3a8dfd86201e3bdbdd6972177ea20b", - "reference": "54d79711ff3a8dfd86201e3bdbdd6972177ea20b", + "url": "https://api.github.com/repos/nette/http/zipball/d7cc833ee186d5139cde5aab43b39ee7aedd6f22", + "reference": "d7cc833ee186d5139cde5aab43b39ee7aedd6f22", "shasum": "" }, "require": { @@ -800,7 +800,10 @@ "tracy/tracy": "^2.8" }, "suggest": { - "ext-fileinfo": "to detect type of uploaded files" + "ext-fileinfo": "to detect MIME type of uploaded files by Nette\\Http\\FileUpload", + "ext-gd": "to use image function in Nette\\Http\\FileUpload", + "ext-intl": "to support punycode by Nette\\Http\\Url", + "ext-session": "to use Nette\\Http\\Session" }, "type": "library", "extra": { @@ -844,9 +847,9 @@ ], "support": { "issues": "https://github.com/nette/http/issues", - "source": "https://github.com/nette/http/tree/v3.2.3" + "source": "https://github.com/nette/http/tree/v3.2.4" }, - "time": "2023-11-02T02:43:54+00:00" + "time": "2024-01-30T18:13:43+00:00" }, { "name": "nette/mail", diff --git a/site/vendor/composer/installed.json b/site/vendor/composer/installed.json index 900736b0e..6c85fd091 100644 --- a/site/vendor/composer/installed.json +++ b/site/vendor/composer/installed.json @@ -857,17 +857,17 @@ }, { "name": "nette/http", - "version": "v3.2.3", - "version_normalized": "3.2.3.0", + "version": "v3.2.4", + "version_normalized": "3.2.4.0", "source": { "type": "git", "url": "https://github.com/nette/http.git", - "reference": "54d79711ff3a8dfd86201e3bdbdd6972177ea20b" + "reference": "d7cc833ee186d5139cde5aab43b39ee7aedd6f22" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nette/http/zipball/54d79711ff3a8dfd86201e3bdbdd6972177ea20b", - "reference": "54d79711ff3a8dfd86201e3bdbdd6972177ea20b", + "url": "https://api.github.com/repos/nette/http/zipball/d7cc833ee186d5139cde5aab43b39ee7aedd6f22", + "reference": "d7cc833ee186d5139cde5aab43b39ee7aedd6f22", "shasum": "" }, "require": { @@ -886,9 +886,12 @@ "tracy/tracy": "^2.8" }, "suggest": { - "ext-fileinfo": "to detect type of uploaded files" + "ext-fileinfo": "to detect MIME type of uploaded files by Nette\\Http\\FileUpload", + "ext-gd": "to use image function in Nette\\Http\\FileUpload", + "ext-intl": "to support punycode by Nette\\Http\\Url", + "ext-session": "to use Nette\\Http\\Session" }, - "time": "2023-11-02T02:43:54+00:00", + "time": "2024-01-30T18:13:43+00:00", "type": "library", "extra": { "branch-alias": { @@ -932,7 +935,7 @@ ], "support": { "issues": "https://github.com/nette/http/issues", - "source": "https://github.com/nette/http/tree/v3.2.3" + "source": "https://github.com/nette/http/tree/v3.2.4" }, "install-path": "../nette/http" }, diff --git a/site/vendor/composer/installed.php b/site/vendor/composer/installed.php index 1765ee4da..d2260cb00 100644 --- a/site/vendor/composer/installed.php +++ b/site/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'spaze/michalspacek.cz', 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => '42ab88f837070774ea34eeab994ea5090654365b', + 'reference' => '1e10bf52e97edbdd135c20dcaf6a81fdad3f565b', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -152,9 +152,9 @@ 'dev_requirement' => false, ), 'nette/http' => array( - 'pretty_version' => 'v3.2.3', - 'version' => '3.2.3.0', - 'reference' => '54d79711ff3a8dfd86201e3bdbdd6972177ea20b', + 'pretty_version' => 'v3.2.4', + 'version' => '3.2.4.0', + 'reference' => 'd7cc833ee186d5139cde5aab43b39ee7aedd6f22', 'type' => 'library', 'install_path' => __DIR__ . '/../nette/http', 'aliases' => array(), @@ -456,7 +456,7 @@ 'spaze/michalspacek.cz' => array( 'pretty_version' => 'dev-main', 'version' => 'dev-main', - 'reference' => '42ab88f837070774ea34eeab994ea5090654365b', + 'reference' => '1e10bf52e97edbdd135c20dcaf6a81fdad3f565b', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), diff --git a/site/vendor/nette/http/composer.json b/site/vendor/nette/http/composer.json index 682344d57..89c31c9c6 100644 --- a/site/vendor/nette/http/composer.json +++ b/site/vendor/nette/http/composer.json @@ -30,7 +30,10 @@ "nette/schema": "<1.2" }, "suggest": { - "ext-fileinfo": "to detect type of uploaded files" + "ext-fileinfo": "to detect MIME type of uploaded files by Nette\\Http\\FileUpload", + "ext-gd": "to use image function in Nette\\Http\\FileUpload", + "ext-session": "to use Nette\\Http\\Session", + "ext-intl": "to support punycode by Nette\\Http\\Url" }, "autoload": { "classmap": ["src/"] diff --git a/site/vendor/nette/http/src/Http/FileUpload.php b/site/vendor/nette/http/src/Http/FileUpload.php index 08a292856..cefbf8d10 100644 --- a/site/vendor/nette/http/src/Http/FileUpload.php +++ b/site/vendor/nette/http/src/Http/FileUpload.php @@ -41,6 +41,9 @@ final class FileUpload /** @var string|false|null */ private $type; + /** @var string|false|null */ + private $extension; + /** @var int */ private $size; @@ -98,9 +101,9 @@ public function getSanitizedName(): string $name = str_replace(['-.', '.-'], '.', $name); $name = trim($name, '.-'); $name = $name === '' ? 'unknown' : $name; - if ($this->isImage()) { + if ($ext = $this->getSuggestedExtension()) { $name = preg_replace('#\.[^.]+$#D', '', $name); - $name .= '.' . ($this->getImageFileExtension() ?? 'unknown'); + $name .= '.' . $ext; } return $name; @@ -134,6 +137,27 @@ public function getContentType(): ?string } + /** + * Returns the appropriate file extension (without the period) corresponding to the detected MIME type. Requires the PHP extension fileinfo. + */ + public function getSuggestedExtension(): ?string + { + if ($this->isOk() && $this->extension === null) { + $exts = finfo_file(finfo_open(FILEINFO_EXTENSION), $this->tmpName); + if ($exts && $exts !== '???') { + return $this->extension = preg_replace('~[/,].*~', '', $exts); + } + [, , $type] = @getimagesize($this->tmpName); // @ - files smaller than 12 bytes causes read error + if ($type) { + return $this->extension = image_type_to_extension($type, false); + } + $this->extension = false; + } + + return $this->extension ?: null; + } + + /** * Returns the size of the uploaded file in bytes. */ @@ -212,8 +236,8 @@ function (string $message) use ($dest): void { /** - * Returns true if the uploaded file is an image supported by PHP. - * Detection is based on its signature, the integrity of the file is not checked. Requires PHP extension fileinfo. + * Returns true if the uploaded file is an image and the format is supported by PHP, so it can be loaded using the toImage() method. + * Detection is based on its signature, the integrity of the file is not checked. Requires PHP extensions fileinfo & gd. */ public function isImage(): bool { @@ -230,7 +254,7 @@ public function isImage(): bool /** - * Loads an image. + * Converts uploaded image to Nette\Utils\Image object. * @throws Nette\Utils\ImageException If the upload was not successful or is not a valid image */ public function toImage(): Nette\Utils\Image @@ -252,12 +276,11 @@ public function getImageSize(): ?array /** * Returns image file extension based on detected content type (without dot). + * @deprecated use getSuggestedExtension() */ public function getImageFileExtension(): ?string { - return $this->isImage() - ? explode('/', $this->getContentType())[1] - : null; + return $this->getSuggestedExtension(); } diff --git a/site/vendor/nette/http/src/Http/RequestFactory.php b/site/vendor/nette/http/src/Http/RequestFactory.php index 125a8cc9d..3c507a3ec 100644 --- a/site/vendor/nette/http/src/Http/RequestFactory.php +++ b/site/vendor/nette/http/src/Http/RequestFactory.php @@ -89,11 +89,11 @@ private function getServer(Url $url): void if ( (isset($_SERVER[$tmp = 'HTTP_HOST']) || isset($_SERVER[$tmp = 'SERVER_NAME'])) - && preg_match('#^([a-z0-9_.-]+|\[[a-f0-9:]+\])(:\d+)?$#Di', $_SERVER[$tmp], $pair) + && ($pair = $this->parseHostAndPort($_SERVER[$tmp])) ) { - $url->setHost(rtrim(strtolower($pair[1]), '.')); - if (isset($pair[2])) { - $url->setPort((int) substr($pair[2], 1)); + $url->setHost($pair[0]); + if (isset($pair[1])) { + $url->setPort($pair[1]); } elseif ($tmp === 'SERVER_NAME' && isset($_SERVER['SERVER_PORT'])) { $url->setPort((int) $_SERVER['SERVER_PORT']); } @@ -321,22 +321,13 @@ private function useForwardedProxy(Url $url): ?string $url->setPort($url->getScheme() === 'https' ? 443 : 80); } - if (isset($proxyParams['host']) && count($proxyParams['host']) === 1) { - $host = $proxyParams['host'][0]; - $startingDelimiterPosition = strpos($host, '['); - if ($startingDelimiterPosition === false) { //IPv4 - $pair = explode(':', $host); - $url->setHost($pair[0]); - if (isset($pair[1])) { - $url->setPort((int) $pair[1]); - } - } else { //IPv6 - $endingDelimiterPosition = strpos($host, ']'); - $url->setHost(substr($host, strpos($host, '[') + 1, $endingDelimiterPosition - 1)); - $pair = explode(':', substr($host, $endingDelimiterPosition)); - if (isset($pair[1])) { - $url->setPort((int) $pair[1]); - } + if ( + isset($proxyParams['host']) && count($proxyParams['host']) === 1 + && ($pair = $this->parseHostAndPort($proxyParams['host'][0])) + ) { + $url->setHost($pair[0]); + if (isset($pair[1])) { + $url->setPort($pair[1]); } } return $remoteAddr ?? null; @@ -378,6 +369,18 @@ private function useNonstandardProxy(Url $url): ?string } + /** @return array{string, ?int}|null */ + private function parseHostAndPort(string $s): ?array + { + return preg_match('#^([a-z0-9_.-]+|\[[a-f0-9:]+])(:\d+)?$#Di', $s, $matches) + ? [ + rtrim(strtolower($matches[1]), '.'), + isset($matches[2]) ? (int) substr($matches[2], 1) : null, + ] + : null; + } + + /** @deprecated */ public function createHttpRequest(): Request { diff --git a/site/vendor/nette/http/src/Http/Url.php b/site/vendor/nette/http/src/Http/Url.php index 351ba5feb..9551e0a8c 100644 --- a/site/vendor/nette/http/src/Http/Url.php +++ b/site/vendor/nette/http/src/Http/Url.php @@ -421,7 +421,7 @@ private static function idnHostToUnicode(string $host): string return idn_to_utf8($host, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46) ?: $host; } - trigger_error('PHP extension idn is not loaded or is too old', E_USER_WARNING); + trigger_error('PHP extension intl is not loaded or is too old', E_USER_WARNING); }