From 6d0d6c22d395fe0b7baf3479d43729e0e2b2dae2 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 22 Feb 2022 09:46:29 +0200 Subject: [PATCH 1/3] Fixed new `Utils::pathinfo()` and `Utils::basename()` being too strict for legacy use [#3542] --- CHANGELOG.md | 1 + system/src/Grav/Common/Assets.php | 9 +++++++-- system/src/Grav/Common/Grav.php | 8 ++++++-- system/src/Grav/Common/Utils.php | 4 ++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b3d19901..3d04d3821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Fixed phpstan issues (All level 2, Framework level 5) 2. [](#bugfix) * Fixed `'mbstring' extension is not loaded` error, use Polyfill instead [#3504](https://github.com/getgrav/grav/pull/3504) + * Fixed new `Utils::pathinfo()` and `Utils::basename()` being too strict for legacy use [#3542](https://github.com/getgrav/grav/issues/3542) # v1.7.30 ## 02/07/2022 diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index 23878a390..621a14041 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -16,8 +16,8 @@ use Grav\Common\Assets\Traits\TestingAssetsTrait; use Grav\Common\Config\Config; use Grav\Framework\Object\PropertyObject; use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator; +use function array_slice; use function call_user_func_array; -use function count; use function func_get_args; use function is_array; @@ -174,6 +174,10 @@ class Assets extends PropertyObject */ public function add($asset) { + if (!$asset) { + return $this; + } + $args = func_get_args(); // More than one asset @@ -198,7 +202,8 @@ class Assets extends PropertyObject call_user_func_array([$this, 'add'], $args); } else { // Get extension - $extension = Utils::pathinfo(parse_url($asset, PHP_URL_PATH), PATHINFO_EXTENSION); + $path = parse_url($asset, PHP_URL_PATH); + $extension = $path ? Utils::pathinfo($path, PATHINFO_EXTENSION) : ''; // JavaScript or CSS if ($extension !== '') { diff --git a/system/src/Grav/Common/Grav.php b/system/src/Grav/Common/Grav.php index 18d490295..b9b44a4df 100644 --- a/system/src/Grav/Common/Grav.php +++ b/system/src/Grav/Common/Grav.php @@ -62,6 +62,7 @@ use function call_user_func_array; use function function_exists; use function get_class; use function in_array; +use function is_array; use function is_callable; use function is_int; use function is_string; @@ -729,14 +730,17 @@ class Grav extends Container */ public function fallbackUrl($path) { + $path_parts = Utils::pathinfo($path); + if (!is_array($path_parts)) { + return false; + } + /** @var Uri $uri */ $uri = $this['uri']; /** @var Config $config */ $config = $this['config']; - $path_parts = Utils::pathinfo($path); - /** @var Pages $pages */ $pages = $this['pages']; $page = $pages->find($path_parts['dirname'], true); diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php index 64c81a927..9ac24c217 100644 --- a/system/src/Grav/Common/Utils.php +++ b/system/src/Grav/Common/Utils.php @@ -994,7 +994,7 @@ abstract class Utils * @param int|null $flags * @return array|string */ - public static function pathinfo(string $path, int $flags = null) + public static function pathinfo($path, int $flags = null) { $path = str_replace(['%2F', '%5C'], ['/', '\\'], rawurlencode($path)); @@ -1020,7 +1020,7 @@ abstract class Utils * @param string $suffix * @return string */ - public static function basename(string $path, string $suffix = ''): string + public static function basename($path, string $suffix = ''): string { return rawurldecode(basename(str_replace(['%2F', '%5C'], '/', rawurlencode($path)), $suffix)); } From a7e82f279a41fbb287044b19c0531bafa1adc6ce Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 22 Feb 2022 11:28:57 +0200 Subject: [PATCH 2/3] Fixed non-standard video html atributes generated by `{{ media.html() }}` [#3540] --- CHANGELOG.md | 1 + .../src/Grav/Common/Media/Traits/MediaPlayerTrait.php | 10 +++++----- .../src/Grav/Common/Media/Traits/VideoMediaTrait.php | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d04d3821..be63eea0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ 2. [](#bugfix) * Fixed `'mbstring' extension is not loaded` error, use Polyfill instead [#3504](https://github.com/getgrav/grav/pull/3504) * Fixed new `Utils::pathinfo()` and `Utils::basename()` being too strict for legacy use [#3542](https://github.com/getgrav/grav/issues/3542) + * Fixed non-standard video html atributes generated by `{{ media.html() }}` [#3540](https://github.com/getgrav/grav/issues/3540) # v1.7.30 ## 02/07/2022 diff --git a/system/src/Grav/Common/Media/Traits/MediaPlayerTrait.php b/system/src/Grav/Common/Media/Traits/MediaPlayerTrait.php index 06cb99ad9..7e59d64b0 100644 --- a/system/src/Grav/Common/Media/Traits/MediaPlayerTrait.php +++ b/system/src/Grav/Common/Media/Traits/MediaPlayerTrait.php @@ -25,7 +25,7 @@ trait MediaPlayerTrait public function controls($status = true) { if ($status) { - $this->attributes['controls'] = true; + $this->attributes['controls'] = 'controls'; } else { unset($this->attributes['controls']); } @@ -42,7 +42,7 @@ trait MediaPlayerTrait public function loop($status = false) { if ($status) { - $this->attributes['loop'] = true; + $this->attributes['loop'] = 'loop'; } else { unset($this->attributes['loop']); } @@ -59,7 +59,7 @@ trait MediaPlayerTrait public function autoplay($status = false) { if ($status) { - $this->attributes['autoplay'] = true; + $this->attributes['autoplay'] = 'autoplay'; } else { unset($this->attributes['autoplay']); } @@ -76,7 +76,7 @@ trait MediaPlayerTrait public function muted($status = false) { if ($status) { - $this->attributes['muted'] = true; + $this->attributes['muted'] = 'muted'; } else { unset($this->attributes['muted']); } @@ -108,6 +108,6 @@ trait MediaPlayerTrait */ public function resetPlayer() { - $this->attributes['controls'] = true; + $this->attributes['controls'] = 'controls'; } } diff --git a/system/src/Grav/Common/Media/Traits/VideoMediaTrait.php b/system/src/Grav/Common/Media/Traits/VideoMediaTrait.php index b16bb53c7..07f0c3f12 100644 --- a/system/src/Grav/Common/Media/Traits/VideoMediaTrait.php +++ b/system/src/Grav/Common/Media/Traits/VideoMediaTrait.php @@ -40,7 +40,7 @@ trait VideoMediaTrait public function playsinline($status = false) { if ($status) { - $this->attributes['playsinline'] = true; + $this->attributes['playsinline'] = 'playsinline'; } else { unset($this->attributes['playsinline']); } From b992d7f18548c31670d2cf1322e01f8eb7681872 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 22 Feb 2022 11:33:27 +0200 Subject: [PATCH 3/3] Composer update --- composer.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.lock b/composer.lock index 06c0bbf38..965a63c1f 100644 --- a/composer.lock +++ b/composer.lock @@ -4356,16 +4356,16 @@ }, { "name": "phar-io/version", - "version": "3.1.1", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "15a90844ad40f127afd244c0cad228de2a80052a" + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/15a90844ad40f127afd244c0cad228de2a80052a", - "reference": "15a90844ad40f127afd244c0cad228de2a80052a", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", "shasum": "" }, "require": { @@ -4401,9 +4401,9 @@ "description": "Library for handling version information and constraints", "support": { "issues": "https://github.com/phar-io/version/issues", - "source": "https://github.com/phar-io/version/tree/3.1.1" + "source": "https://github.com/phar-io/version/tree/3.2.1" }, - "time": "2022-02-07T21:56:48+00:00" + "time": "2022-02-21T01:04:05+00:00" }, { "name": "phpdocumentor/reflection-common",