From f686e0ac6453b56253b4f89a570d832d5b25ed5a Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 22 Oct 2024 14:10:03 +0100 Subject: [PATCH 1/3] Added extra checks in Uri::getContentType() --- system/src/Grav/Common/Uri.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 2d4386017..dcd9c27a8 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -1407,14 +1407,13 @@ class Uri */ public function getContentType($short = true) { - if (isset($_SERVER['CONTENT_TYPE'])) { - $content_type = $_SERVER['CONTENT_TYPE']; + $content_type = $_SERVER['CONTENT_TYPE'] ?? $_SERVER['HTTP_CONTENT_TYPE'] ?? $_SERVER['HTTP_ACCEPT'] ?? null; + if ($content_type) { if ($short) { return Utils::substrToString($content_type, ';'); } - return $content_type; } - return null; + return $content_type; } /** From 6fa63197a0104ce2c5902a7ecb65da51a9597f96 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 22 Oct 2024 14:10:18 +0100 Subject: [PATCH 2/3] Fallback to extension on Flex-Objects json check --- system/src/Grav/Framework/Flex/FlexCollection.php | 2 +- system/src/Grav/Framework/Flex/FlexObject.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Framework/Flex/FlexCollection.php b/system/src/Grav/Framework/Flex/FlexCollection.php index cfa91008e..25dcd9d76 100644 --- a/system/src/Grav/Framework/Flex/FlexCollection.php +++ b/system/src/Grav/Framework/Flex/FlexCollection.php @@ -440,7 +440,7 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface ] + $context ); - if ($debugger->enabled() && $grav['uri']->getContentType() !== 'application/json') { + if ($debugger->enabled() && ($grav['uri']->getContentType() !== 'application/json' || $grav['uri']->extension() !== 'json')) { $output = "\n\n{$output}\n\n"; } diff --git a/system/src/Grav/Framework/Flex/FlexObject.php b/system/src/Grav/Framework/Flex/FlexObject.php index 58bd7eb4d..01295fec9 100644 --- a/system/src/Grav/Framework/Flex/FlexObject.php +++ b/system/src/Grav/Framework/Flex/FlexObject.php @@ -627,7 +627,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface ] + $context ); - if ($debugger->enabled() && $grav['uri']->getContentType() !== 'application/json') { + if ($debugger->enabled() && ($grav['uri']->getContentType() !== 'application/json' || $grav['uri']->extension() !== 'json')) { $name = $this->getKey() . ' (' . $type . ')'; $output = "\n\n{$output}\n\n"; } From e2257a9783287f05feaeb8544b5283d356ec8acd Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Tue, 22 Oct 2024 15:29:47 +0100 Subject: [PATCH 3/3] logic fix --- system/src/Grav/Framework/Flex/FlexCollection.php | 3 ++- system/src/Grav/Framework/Flex/FlexObject.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Framework/Flex/FlexCollection.php b/system/src/Grav/Framework/Flex/FlexCollection.php index 25dcd9d76..3e9302cb8 100644 --- a/system/src/Grav/Framework/Flex/FlexCollection.php +++ b/system/src/Grav/Framework/Flex/FlexCollection.php @@ -440,7 +440,8 @@ class FlexCollection extends ObjectCollection implements FlexCollectionInterface ] + $context ); - if ($debugger->enabled() && ($grav['uri']->getContentType() !== 'application/json' || $grav['uri']->extension() !== 'json')) { + if ($debugger->enabled() && + !($grav['uri']->getContentType() === 'application/json' || $grav['uri']->extension() === 'json')) { $output = "\n\n{$output}\n\n"; } diff --git a/system/src/Grav/Framework/Flex/FlexObject.php b/system/src/Grav/Framework/Flex/FlexObject.php index 01295fec9..14f28f9b6 100644 --- a/system/src/Grav/Framework/Flex/FlexObject.php +++ b/system/src/Grav/Framework/Flex/FlexObject.php @@ -627,7 +627,8 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface ] + $context ); - if ($debugger->enabled() && ($grav['uri']->getContentType() !== 'application/json' || $grav['uri']->extension() !== 'json')) { + if ($debugger->enabled() && + !($grav['uri']->getContentType() === 'application/json' || $grav['uri']->extension() === 'json')) { $name = $this->getKey() . ' (' . $type . ')'; $output = "\n\n{$output}\n\n"; }