From 216560ecc96ecd3c68277e5b760a43ca7b322ada Mon Sep 17 00:00:00 2001 From: Derek Date: Thu, 7 Jan 2021 21:14:29 -0700 Subject: [PATCH 1/2] Fixed an issue in isJSON that was breaking it if the content type header had the encoding in it as well. --- system/HTTP/Message.php | 11 +++++++++-- tests/system/HTTP/MessageTest.php | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/system/HTTP/Message.php b/system/HTTP/Message.php index 68fc59a8a4b3..a1d5b8de2c18 100644 --- a/system/HTTP/Message.php +++ b/system/HTTP/Message.php @@ -142,7 +142,14 @@ public function getProtocolVersion(): string */ public function isJSON() { - return $this->hasHeader('Content-Type') - && $this->header('Content-Type')->getValue() === 'application/json'; + if (! $this->hasHeader('Content-Type')) + { + return false; + } + + $header = $this->header('Content-Type')->getValue(); + $parts = explode(';', $header); + + return in_array('application/json', $parts); } } diff --git a/tests/system/HTTP/MessageTest.php b/tests/system/HTTP/MessageTest.php index d2bc8aa7f89a..3972a63fdd33 100644 --- a/tests/system/HTTP/MessageTest.php +++ b/tests/system/HTTP/MessageTest.php @@ -349,4 +349,10 @@ public function testIsJsonReturnsTrue() $this->assertTrue($this->message->isJSON()); } + public function testIsJsonWorksWithExtendedContentType() + { + $this->message->setHeader('Content-Type', 'application/json;charset=UTF-8'); + $this->assertTrue($this->message->isJSON()); + } + } From 50de15c336f8b14bddb731455552229a5d8761af Mon Sep 17 00:00:00 2001 From: Derek Date: Thu, 7 Jan 2021 21:24:42 -0700 Subject: [PATCH 2/2] Fixing a rector issue --- system/HTTP/Message.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/HTTP/Message.php b/system/HTTP/Message.php index a1d5b8de2c18..793ed5642c17 100644 --- a/system/HTTP/Message.php +++ b/system/HTTP/Message.php @@ -150,6 +150,6 @@ public function isJSON() $header = $this->header('Content-Type')->getValue(); $parts = explode(';', $header); - return in_array('application/json', $parts); + return in_array('application/json', $parts, true); } }