From 8f0443a73ded13117efd8ec029046044b5867dfe Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 23 Mar 2022 13:05:54 +0200 Subject: [PATCH 1/9] Fixed phpstan issues, composer update --- composer.lock | 95 +++++++++---------- .../Common/Flex/Types/Pages/PageObject.php | 1 + .../Common/Twig/Extension/GravExtension.php | 6 +- 3 files changed, 49 insertions(+), 53 deletions(-) diff --git a/composer.lock b/composer.lock index d0dc8dfd3..2a9fd9e37 100644 --- a/composer.lock +++ b/composer.lock @@ -730,16 +730,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "1.8.3", + "version": "1.8.5", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "1afdd860a2566ed3c2b0b4a3de6e23434a79ec85" + "reference": "337e3ad8e5716c15f9657bd214d16cc5e69df268" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/1afdd860a2566ed3c2b0b4a3de6e23434a79ec85", - "reference": "1afdd860a2566ed3c2b0b4a3de6e23434a79ec85", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/337e3ad8e5716c15f9657bd214d16cc5e69df268", + "reference": "337e3ad8e5716c15f9657bd214d16cc5e69df268", "shasum": "" }, "require": { @@ -820,7 +820,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/1.8.3" + "source": "https://github.com/guzzle/psr7/tree/1.8.5" }, "funding": [ { @@ -836,7 +836,7 @@ "type": "tidelift" } ], - "time": "2021-10-05T13:56:00+00:00" + "time": "2022-03-20T21:51:18+00:00" }, { "name": "itsgoingd/clockwork", @@ -1230,16 +1230,16 @@ }, { "name": "monolog/monolog", - "version": "1.26.1", + "version": "1.27.0", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "c6b00f05152ae2c9b04a448f99c7590beb6042f5" + "reference": "52ebd235c1f7e0d5e1b16464b695a28335f8e44a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/c6b00f05152ae2c9b04a448f99c7590beb6042f5", - "reference": "c6b00f05152ae2c9b04a448f99c7590beb6042f5", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/52ebd235c1f7e0d5e1b16464b695a28335f8e44a", + "reference": "52ebd235c1f7e0d5e1b16464b695a28335f8e44a", "shasum": "" }, "require": { @@ -1300,7 +1300,7 @@ ], "support": { "issues": "https://github.com/Seldaek/monolog/issues", - "source": "https://github.com/Seldaek/monolog/tree/1.26.1" + "source": "https://github.com/Seldaek/monolog/tree/1.27.0" }, "funding": [ { @@ -1312,7 +1312,7 @@ "type": "tidelift" } ], - "time": "2021-05-28T08:32:12+00:00" + "time": "2022-03-13T20:29:46+00:00" }, { "name": "multiavatar/multiavatar-php", @@ -3491,16 +3491,16 @@ }, { "name": "codeception/codeception", - "version": "4.1.30", + "version": "4.1.31", "source": { "type": "git", "url": "https://github.com/Codeception/Codeception.git", - "reference": "a035d77d070fa57fad438e07a65447aeca248c45" + "reference": "15524571ae0686a7facc2eb1f40f600e5bbce9e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Codeception/Codeception/zipball/a035d77d070fa57fad438e07a65447aeca248c45", - "reference": "a035d77d070fa57fad438e07a65447aeca248c45", + "url": "https://api.github.com/repos/Codeception/Codeception/zipball/15524571ae0686a7facc2eb1f40f600e5bbce9e5", + "reference": "15524571ae0686a7facc2eb1f40f600e5bbce9e5", "shasum": "" }, "require": { @@ -3577,7 +3577,7 @@ ], "support": { "issues": "https://github.com/Codeception/Codeception/issues", - "source": "https://github.com/Codeception/Codeception/tree/4.1.30" + "source": "https://github.com/Codeception/Codeception/tree/4.1.31" }, "funding": [ { @@ -3585,7 +3585,7 @@ "type": "open_collective" } ], - "time": "2022-03-05T18:12:30+00:00" + "time": "2022-03-13T17:07:08+00:00" }, { "name": "codeception/lib-asserts", @@ -4025,16 +4025,16 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.4.1", + "version": "7.4.2", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "ee0a041b1760e6a53d2a39c8c34115adc2af2c79" + "reference": "ac1ec1cd9b5624694c3a40be801d94137afb12b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ee0a041b1760e6a53d2a39c8c34115adc2af2c79", - "reference": "ee0a041b1760e6a53d2a39c8c34115adc2af2c79", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ac1ec1cd9b5624694c3a40be801d94137afb12b4", + "reference": "ac1ec1cd9b5624694c3a40be801d94137afb12b4", "shasum": "" }, "require": { @@ -4129,7 +4129,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.4.1" + "source": "https://github.com/guzzle/guzzle/tree/7.4.2" }, "funding": [ { @@ -4145,7 +4145,7 @@ "type": "tidelift" } ], - "time": "2021-12-06T18:43:05+00:00" + "time": "2022-03-20T14:16:28+00:00" }, { "name": "guzzlehttp/promises", @@ -4686,16 +4686,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.4.8", + "version": "1.4.10", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "2a6d6704b17c4db6190cc3104056c0aad740cb15" + "reference": "898c479c39caa727bedf4311dd294a8f4e250e72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/2a6d6704b17c4db6190cc3104056c0aad740cb15", - "reference": "2a6d6704b17c4db6190cc3104056c0aad740cb15", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/898c479c39caa727bedf4311dd294a8f4e250e72", + "reference": "898c479c39caa727bedf4311dd294a8f4e250e72", "shasum": "" }, "require": { @@ -4709,11 +4709,6 @@ "phpstan.phar" ], "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, "autoload": { "files": [ "bootstrap.php" @@ -4726,7 +4721,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.4.8" + "source": "https://github.com/phpstan/phpstan/tree/1.4.10" }, "funding": [ { @@ -4746,7 +4741,7 @@ "type": "tidelift" } ], - "time": "2022-03-04T13:03:56+00:00" + "time": "2022-03-14T10:25:45+00:00" }, { "name": "phpstan/phpstan-deprecation-rules", @@ -5118,16 +5113,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.18", + "version": "9.5.19", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "1b5856028273bfd855e60a887278857d872ec67a" + "reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1b5856028273bfd855e60a887278857d872ec67a", - "reference": "1b5856028273bfd855e60a887278857d872ec67a", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/35ea4b7f3acabb26f4bb640f8c30866c401da807", + "reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807", "shasum": "" }, "require": { @@ -5157,7 +5152,7 @@ "sebastian/global-state": "^5.0.1", "sebastian/object-enumerator": "^4.0.3", "sebastian/resource-operations": "^3.0.3", - "sebastian/type": "^2.3.4", + "sebastian/type": "^3.0", "sebastian/version": "^3.0.2" }, "require-dev": { @@ -5205,7 +5200,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.18" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.19" }, "funding": [ { @@ -5217,7 +5212,7 @@ "type": "github" } ], - "time": "2022-03-08T06:52:28+00:00" + "time": "2022-03-15T09:57:31+00:00" }, { "name": "psr/http-client", @@ -6128,28 +6123,28 @@ }, { "name": "sebastian/type", - "version": "2.3.4", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914" + "reference": "b233b84bc4465aff7b57cf1c4bc75c86d00d6dad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b8cd8a1c753c90bc1a0f5372170e3e489136f914", - "reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b233b84bc4465aff7b57cf1c4bc75c86d00d6dad", + "reference": "b233b84bc4465aff7b57cf1c4bc75c86d00d6dad", "shasum": "" }, "require": { "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^9.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.3-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -6172,7 +6167,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/2.3.4" + "source": "https://github.com/sebastianbergmann/type/tree/3.0.0" }, "funding": [ { @@ -6180,7 +6175,7 @@ "type": "github" } ], - "time": "2021-06-15T12:49:02+00:00" + "time": "2022-03-15T09:54:48+00:00" }, { "name": "sebastian/version", diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php index a05f0eb42..ebf3c2712 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php +++ b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php @@ -242,6 +242,7 @@ class PageObject extends FlexPageObject { /** @var PageCollection $siblings */ $siblings = $variables['siblings']; + /** @var PageObject $sibling */ foreach ($siblings as $sibling) { $sibling->save(false); } diff --git a/system/src/Grav/Common/Twig/Extension/GravExtension.php b/system/src/Grav/Common/Twig/Extension/GravExtension.php index 399c08995..a2a76b317 100644 --- a/system/src/Grav/Common/Twig/Extension/GravExtension.php +++ b/system/src/Grav/Common/Twig/Extension/GravExtension.php @@ -550,9 +550,9 @@ class GravExtension extends AbstractExtension implements GlobalsInterface } /** - * @param $str - * @param $search - * @param $replace + * @param string|mixed $str + * @param string $search + * @param string $replace * @return string|mixed */ public function replaceLastFilter($str, $search, $replace) From c9c23c6c4f77d0628126e2e839f477794cb8a59f Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 23 Mar 2022 15:47:45 +0200 Subject: [PATCH 2/9] Better fix for `system.cache.gzip: true` --- CHANGELOG.md | 2 +- .../src/Grav/Common/Errors/SystemFacade.php | 21 +++++++++++++++++++ system/src/Grav/Common/Grav.php | 8 +++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a3590c4e..165516638 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ - `text`, `url`, `hidden`, `commalist`: 2048 - `text` (multiline), `textarea`: 65536 3. [](#bugfix) - * Fixed issue with `system.cache.gzip: true` resulted in admin "Fetch Failed" for PHP 8.0+ + * Fixed issue with `system.cache.gzip: true` resulted in admin "Fetch Failed" for PHP 8.0.17 and PHP 8.1.4 [PHP bug #8218](https://github.com/php/php-src/issues/8218). * Fix for multi-lang issues with Security Report # v1.7.31 diff --git a/system/src/Grav/Common/Errors/SystemFacade.php b/system/src/Grav/Common/Errors/SystemFacade.php index edf2b5338..e13b0f6e7 100644 --- a/system/src/Grav/Common/Errors/SystemFacade.php +++ b/system/src/Grav/Common/Errors/SystemFacade.php @@ -43,4 +43,25 @@ class SystemFacade extends \Whoops\Util\SystemFacade $handler(); } } + + + /** + * @param int $httpCode + * + * @return int + */ + public function setHttpResponseCode($httpCode) + { + if (!headers_sent()) { + // Ensure that no 'location' header is present as otherwise this + // will override the HTTP code being set here, and mask the + // expected error page. + header_remove('location'); + + // Work around PHP bug #8218 (8.0.17 & 8.1.4). + header_remove('Content-Encoding'); + } + + return http_response_code($httpCode); + } } diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 68a0bf3cf..7e3dcaff8 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -350,14 +350,12 @@ class Grav extends Container */ public function cleanOutputBuffers(): void { - /** @var Config $config */ - $config = $this['config']; - $gzip_enabled = (int) $config->get('system.cache.gzip'); - // Make sure nothing extra gets written to the response. - while (ob_get_level() > 2 + $gzip_enabled) { + while (ob_get_level()) { ob_end_clean(); } + // Work around PHP bug #8218 (8.0.17 & 8.1.4). + header_remove('Content-Encoding'); } /** From 236c38e65ddb7c487cf4d9f4b43a045c1c05d18e Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 23 Mar 2022 15:49:12 +0200 Subject: [PATCH 3/9] Changelog update --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 165516638..1bf0b6791 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ - `text`, `url`, `hidden`, `commalist`: 2048 - `text` (multiline), `textarea`: 65536 3. [](#bugfix) - * Fixed issue with `system.cache.gzip: true` resulted in admin "Fetch Failed" for PHP 8.0.17 and PHP 8.1.4 [PHP bug #8218](https://github.com/php/php-src/issues/8218). + * Fixed issue with `system.cache.gzip: true` resulted in "Fetch Failed" for PHP 8.0.17 and PHP 8.1.4 [PHP issue #8218](https://github.com/php/php-src/issues/8218). * Fix for multi-lang issues with Security Report # v1.7.31 From b0add67cdd0d74c00b0857a064b9ee34b422e33f Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 25 Mar 2022 09:35:33 +0200 Subject: [PATCH 4/9] Flex search() optimizations --- CHANGELOG.md | 2 +- .../Grav/Framework/Flex/FlexCollection.php | 4 ++ .../src/Grav/Framework/Flex/FlexDirectory.php | 38 +++++++++++++++++++ system/src/Grav/Framework/Flex/FlexIndex.php | 4 ++ system/src/Grav/Framework/Flex/FlexObject.php | 14 ++----- 5 files changed, 50 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bf0b6791..de6e63544 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ - `text`, `url`, `hidden`, `commalist`: 2048 - `text` (multiline), `textarea`: 65536 3. [](#bugfix) - * Fixed issue with `system.cache.gzip: true` resulted in "Fetch Failed" for PHP 8.0.17 and PHP 8.1.4 [PHP issue #8218](https://github.com/php/php-src/issues/8218). + * Fixed issue with `system.cache.gzip: true` resulted in "Fetch Failed" for PHP 8.0.17 and PHP 8.1.4 [PHP issue #8218](https://github.com/php/php-src/issues/8218) * Fix for multi-lang issues with Security Report # v1.7.31 diff --git a/system/src/Grav/Framework/Flex/FlexCollection.php b/system/src/Grav/Framework/Flex/FlexCollection.php index 186c60abc..9c5b16c31 100644 --- a/system/src/Grav/Framework/Flex/FlexCollection.php +++ b/system/src/Grav/Framework/Flex/FlexCollection.php @@ -147,6 +147,10 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface */ public function search(string $search, $properties = null, array $options = null) { + $directory = $this->getFlexDirectory(); + $properties = $directory->getSearchProperties($properties); + $options = $directory->getSearchOptions($options); + $matching = $this->call('search', [$search, $properties, $options]); $matching = array_filter($matching); diff --git a/system/src/Grav/Framework/Flex/FlexDirectory.php b/system/src/Grav/Framework/Flex/FlexDirectory.php index f96633b31..b9df07597 100644 --- a/system/src/Grav/Framework/Flex/FlexDirectory.php +++ b/system/src/Grav/Framework/Flex/FlexDirectory.php @@ -170,6 +170,44 @@ class FlexDirectory implements FlexDirectoryInterface return null === $name ? $this->config : $this->config->get($name, $default); } + /** + * @param string|string[]|null + * @return array + */ + public function getSearchProperties($properties = null): array + { + if (null !== $properties) { + return (array)$properties; + } + + $properties = $this->getConfig('data.search.fields'); + if (!$properties) { + $fields = $this->getConfig('admin.views.list.fields') ?? $this->getConfig('admin.list.fields', []); + foreach ($fields as $property => $value) { + if (!empty($value['link'])) { + $properties[] = $property; + } + } + } + + return $properties; + } + + /** + * @param array|null $options + * @return array + */ + public function getSearchOptions(array $options = null): array + { + if (empty($options['merge'])) { + return $options ?? (array)$this->getConfig('data.search.options'); + } + + unset($options['merge']); + + return $options + (array)$this->getConfig('data.search.options'); + } + /** * @param string|null $name * @param array $options diff --git a/system/src/Grav/Framework/Flex/FlexIndex.php b/system/src/Grav/Framework/Flex/FlexIndex.php index 54438af51..d02065fb7 100644 --- a/system/src/Grav/Framework/Flex/FlexIndex.php +++ b/system/src/Grav/Framework/Flex/FlexIndex.php @@ -162,6 +162,10 @@ class FlexIndex extends ObjectIndex implements FlexIndexInterface */ public function search(string $search, $properties = null, array $options = null) { + $directory = $this->getFlexDirectory(); + $properties = $directory->getSearchProperties($properties); + $options = $directory->getSearchOptions($options); + return $this->__call('search', [$search, $properties, $options]); } diff --git a/system/src/Grav/Framework/Flex/FlexObject.php b/system/src/Grav/Framework/Flex/FlexObject.php index afc656c04..3808b2c64 100644 --- a/system/src/Grav/Framework/Flex/FlexObject.php +++ b/system/src/Grav/Framework/Flex/FlexObject.php @@ -287,17 +287,9 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface */ public function search(string $search, $properties = null, array $options = null): float { - $properties = (array)($properties ?? $this->getFlexDirectory()->getConfig('data.search.fields')); - if (!$properties) { - $fields = $this->getFlexDirectory()->getConfig('admin.views.list.fields') ?? $this->getFlexDirectory()->getConfig('admin.list.fields', []); - foreach ($fields as $property => $value) { - if (!empty($value['link'])) { - $properties[] = $property; - } - } - } - - $options = $options ?? (array)$this->getFlexDirectory()->getConfig('data.search.options'); + $directory = $this->getFlexDirectory(); + $properties = $directory->getSearchProperties($properties); + $options = $directory->getSearchOptions($options); $weight = 0; foreach ($properties as $property) { From 5a355fb94ec45d34a6580719e9e37c899615534f Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 25 Mar 2022 10:33:05 +0200 Subject: [PATCH 5/9] Fixed page search not working with selected language [#3316] --- CHANGELOG.md | 1 + .../Common/Flex/Types/Pages/PageIndex.php | 7 ++--- .../Common/Flex/Types/Pages/PageObject.php | 28 ++++++++++++------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de6e63544..443e87ab1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ 3. [](#bugfix) * Fixed issue with `system.cache.gzip: true` resulted in "Fetch Failed" for PHP 8.0.17 and PHP 8.1.4 [PHP issue #8218](https://github.com/php/php-src/issues/8218) * Fix for multi-lang issues with Security Report + * Fixed page search not working with selected language [#3316](https://github.com/getgrav/grav/issues/3316) # v1.7.31 ## 03/14/2022 diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php b/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php index f3978bc1d..870978b7e 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php +++ b/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php @@ -454,7 +454,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface continue; } - // Get the main key without template and langauge. + // Get the main key without template and language. [$main_key,] = explode('|', $entry['storage_key'] . '|', 2); // Update storage key and language. @@ -527,10 +527,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface $language = $options['lang']; $status = 'error'; - $msg = null; $response = []; - $children = null; - $sub_route = null; $extra = null; // Handle leaf_route @@ -610,7 +607,7 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface $children = $page->children(); /** @var PageIndex $children */ $children = $children->getIndex(); - $selectedChildren = $children->filterBy($filters, true); + $selectedChildren = $children->filterBy($filters + ['language' => $language], true); /** @var Header $header */ $header = $page->header(); diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php index ebf3c2712..6a0afdb84 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php +++ b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php @@ -586,38 +586,46 @@ class PageObject extends FlexPageObject */ public function filterBy(array $filters, bool $recursive = false): bool { + $language = $filters['language'] ?? null; + if (null !== $language) { + /** @var PageObject $test */ + $test = $this->getTranslation($language) ?? $this; + } else { + $test = $this; + } + foreach ($filters as $key => $value) { switch ($key) { case 'search': - $matches = $this->search((string)$value) > 0.0; + $matches = $test->search((string)$value) > 0.0; break; case 'page_type': $types = $value ? explode(',', $value) : []; - $matches = in_array($this->template(), $types, true); + $matches = in_array($test->template(), $types, true); break; case 'extension': - $matches = Utils::contains((string)$value, $this->extension()); + $matches = Utils::contains((string)$value, $test->extension()); break; case 'routable': - $matches = $this->isRoutable() === (bool)$value; + $matches = $test->isRoutable() === (bool)$value; break; case 'published': - $matches = $this->isPublished() === (bool)$value; + $matches = $test->isPublished() === (bool)$value; break; case 'visible': - $matches = $this->isVisible() === (bool)$value; + $matches = $test->isVisible() === (bool)$value; break; case 'module': - $matches = $this->isModule() === (bool)$value; + $matches = $test->isModule() === (bool)$value; break; case 'page': - $matches = $this->isPage() === (bool)$value; + $matches = $test->isPage() === (bool)$value; break; case 'folder': - $matches = $this->isPage() === !$value; + $matches = $test->isPage() === !$value; break; case 'translated': - $matches = $this->hasTranslation() === (bool)$value; + $matches = $test->hasTranslation() === (bool)$value; break; default: $matches = true; From 2830ba91205b4e3ea49a8cdbc1f74a5f03e6f70b Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Mon, 28 Mar 2022 11:36:48 -0600 Subject: [PATCH 6/9] prepare for release --- CHANGELOG.md | 2 +- system/defines.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 443e87ab1..c35fd6b33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # v1.7.32 -## mm/dd/2022 +## 03/28/2022 1. [](#new) * Added `|replace_last(search, replace)` filter diff --git a/system/defines.php b/system/defines.php index 5f743db3f..f0d30ba6e 100644 --- a/system/defines.php +++ b/system/defines.php @@ -9,7 +9,7 @@ // Some standard defines define('GRAV', true); -define('GRAV_VERSION', '1.7.31'); +define('GRAV_VERSION', '1.7.32'); define('GRAV_SCHEMA', '1.7.0_2020-11-20_1'); define('GRAV_TESTING', false); From 7c2b21fb608a86942a259905151f5ceb936dbca4 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 29 Mar 2022 21:35:02 +0300 Subject: [PATCH 7/9] Fixed missing changes in yaml & markdown files if saved multiple times during the same second because of a caching issue --- CHANGELOG.md | 6 ++++++ system/src/Grav/Common/File/CompiledFile.php | 12 ++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c35fd6b33..4565f9f0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.7.33 +## mm/dd/2022 + +1. [](#bugfix) + * Fixed missing changes in yaml & markdown files if saved multiple times during the same second because of a caching issue + # v1.7.32 ## 03/28/2022 diff --git a/system/src/Grav/Common/File/CompiledFile.php b/system/src/Grav/Common/File/CompiledFile.php index 222842278..ce133a600 100644 --- a/system/src/Grav/Common/File/CompiledFile.php +++ b/system/src/Grav/Common/File/CompiledFile.php @@ -32,9 +32,10 @@ trait CompiledFile public function content($var = null) { try { + $filename = $this->filename; // If nothing has been loaded, attempt to get pre-compiled version of the file first. if ($var === null && $this->raw === null && $this->content === null) { - $key = md5($this->filename); + $key = md5($filename); $file = PhpFile::instance(CACHE_DIR . "compiled/files/{$key}{$this->extension}.php"); $modified = $this->modified(); @@ -48,13 +49,15 @@ trait CompiledFile $class = get_class($this); + $size = filesize($filename); $cache = $file->exists() ? $file->content() : null; // Load real file if cache isn't up to date (or is invalid). if (!isset($cache['@class']) || $cache['@class'] !== $class || $cache['modified'] !== $modified - || $cache['filename'] !== $this->filename + || ($cache['size'] ?? null) !== $size + || $cache['filename'] !== $filename ) { // Attempt to lock the file for writing. try { @@ -67,8 +70,9 @@ trait CompiledFile $data = (array)$this->decode($this->raw()); $cache = [ '@class' => $class, - 'filename' => $this->filename, + 'filename' => $filename, 'modified' => $modified, + 'size' => $size, 'data' => $data ]; @@ -89,7 +93,7 @@ trait CompiledFile $this->content = $cache['data']; } } catch (Exception $e) { - throw new RuntimeException(sprintf('Failed to read %s: %s', Utils::basename($this->filename), $e->getMessage()), 500, $e); + throw new RuntimeException(sprintf('Failed to read %s: %s', Utils::basename($filename), $e->getMessage()), 500, $e); } return parent::content($var); From a092aed4ed71ad3a9d2ae3724d81fea6ae12e51a Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 30 Mar 2022 12:00:59 +0300 Subject: [PATCH 8/9] When saving yaml and markdown, create also a cached version of the file and recompile it in opcache --- CHANGELOG.md | 4 +- system/src/Grav/Common/File/CompiledFile.php | 71 ++++++++++++++++++-- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4565f9f0d..59f4a1129 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ # v1.7.33 ## mm/dd/2022 -1. [](#bugfix) +1. [](#improved) + * When saving yaml and markdown, create also a cached version of the file and recompile it in opcache +2. [](#bugfix) * Fixed missing changes in yaml & markdown files if saved multiple times during the same second because of a caching issue # v1.7.32 diff --git a/system/src/Grav/Common/File/CompiledFile.php b/system/src/Grav/Common/File/CompiledFile.php index ce133a600..9393ab70f 100644 --- a/system/src/Grav/Common/File/CompiledFile.php +++ b/system/src/Grav/Common/File/CompiledFile.php @@ -10,6 +10,8 @@ namespace Grav\Common\File; use Exception; +use Grav\Common\Debugger; +use Grav\Common\Grav; use Grav\Common\Utils; use RocketTheme\Toolbox\File\PhpFile; use RuntimeException; @@ -61,9 +63,13 @@ trait CompiledFile ) { // Attempt to lock the file for writing. try { - $file->lock(false); + $locked = $file->lock(false); } catch (Exception $e) { - // Another process has locked the file; we will check this in a bit. + $locked = false; + + /** @var Debugger $debugger */ + $debugger = Grav::instance()['debugger']; + $debugger->addMessage(sprintf('%s(): Cannot obtain a lock for compiling cache file for %s: %s', __METHOD__, $this->filename, $e->getMessage()), 'warning'); } // Decode RAW file into compiled array. @@ -77,14 +83,17 @@ trait CompiledFile ]; // If compiled file wasn't already locked by another process, save it. - if ($file->locked() !== false) { + if ($locked) { $file->save($cache); $file->unlock(); // Compile cached file into bytecode cache - if (function_exists('opcache_invalidate')) { + if (function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN)) { + $lockName = $file->filename(); + // Silence error if function exists, but is restricted. - @opcache_invalidate($file->filename(), true); + @opcache_invalidate($lockName, true); + @opcache_compile_file($lockName); } } } @@ -99,6 +108,58 @@ trait CompiledFile return parent::content($var); } + /** + * Save file. + * + * @param mixed $data Optional data to be saved, usually array. + * @return void + * @throws RuntimeException + */ + public function save($data = null) + { + // Make sure that the cache file is always up to date! + $key = md5($this->filename); + $file = PhpFile::instance(CACHE_DIR . "compiled/files/{$key}{$this->extension}.php"); + try { + $locked = $file->lock(); + } catch (Exception $e) { + $locked = false; + + /** @var Debugger $debugger */ + $debugger = Grav::instance()['debugger']; + $debugger->addMessage(sprintf('%s(): Cannot obtain a lock for compiling cache file for %s: %s', __METHOD__, $this->filename, $e->getMessage()), 'warning'); + } + + parent::save($data); + + if ($locked) { + $modified = $this->modified(); + $filename = $this->filename; + $class = get_class($this); + $size = filesize($filename); + + // Decode data into compiled array. + $cache = [ + '@class' => $class, + 'filename' => $filename, + 'modified' => $modified, + 'size' => $size, + 'data' => $data + ]; + + $file->save($cache); + $file->unlock(); + + // Compile cached file into bytecode cache + if (function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN)) { + $lockName = $file->filename(); + // Silence error if function exists, but is restricted. + @opcache_invalidate($lockName, true); + @opcache_compile_file($lockName); + } + } + } + /** * Serialize file. * From 1c0ed43afa5dc14169e6aa693b38e1a2f7aecad9 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Wed, 30 Mar 2022 13:26:11 +0300 Subject: [PATCH 9/9] Fixed XSS check not detecting onX events without quotes --- CHANGELOG.md | 1 + system/src/Grav/Common/Security.php | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59f4a1129..0c993524c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * When saving yaml and markdown, create also a cached version of the file and recompile it in opcache 2. [](#bugfix) * Fixed missing changes in yaml & markdown files if saved multiple times during the same second because of a caching issue + * Fixed XSS check not detecting onX events without quotes # v1.7.32 ## 03/28/2022 diff --git a/system/src/Grav/Common/Security.php b/system/src/Grav/Common/Security.php index 11153a625..982618544 100644 --- a/system/src/Grav/Common/Security.php +++ b/system/src/Grav/Common/Security.php @@ -219,7 +219,8 @@ class Security $string = html_entity_decode($string, ENT_NOQUOTES | ENT_HTML5, 'UTF-8'); // Strip whitespace characters - $string = preg_replace('!\s!u', '', $string); + $string = preg_replace('!\s!u', ' ', $string); + $stripped = preg_replace('!\s!u', '', $string); // Set the patterns we'll test against $patterns = [ @@ -242,7 +243,7 @@ class Security // Iterate over rules and return label if fail foreach ($patterns as $name => $regex) { if (!empty($enabled_rules[$name])) { - if (preg_match($regex, $string) || preg_match($regex, $orig)) { + if (preg_match($regex, $string) || preg_match($regex, $stripped) || preg_match($regex, $orig)) { return $name; } }