Skip to content

Commit

Permalink
Update nette/http to v3.2.4, not to 3.3.0
Browse files Browse the repository at this point in the history
Because of nette/http#233
  • Loading branch information
spaze committed Feb 16, 2024
1 parent 1e10bf5 commit dbcbd13
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 52 deletions.
2 changes: 1 addition & 1 deletion site/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 11 additions & 8 deletions site/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions site/vendor/composer/installed.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions site/vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
5 changes: 4 additions & 1 deletion site/vendor/nette/http/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"]
Expand Down
39 changes: 31 additions & 8 deletions site/vendor/nette/http/src/Http/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ final class FileUpload
/** @var string|false|null */
private $type;

/** @var string|false|null */
private $extension;

/** @var int */
private $size;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
{
Expand All @@ -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
Expand All @@ -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();
}


Expand Down
43 changes: 23 additions & 20 deletions site/vendor/nette/http/src/Http/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion site/vendor/nette/http/src/Http/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down

0 comments on commit dbcbd13

Please sign in to comment.