Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing a bug in Message::isJSON #4081

Merged
merged 2 commits into from
Jan 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions system/HTTP/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, true);
Comment on lines +150 to +153
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$header = $this->header('Content-Type')->getValue();
$parts = explode(';', $header);
return in_array('application/json', $parts, true);
return in_array('application/json', explode(';', $this->header('Content-Type')->getValue()), true);

use one line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mostafakhudair that's harder to read/understand the flow.

}
}
6 changes: 6 additions & 0 deletions tests/system/HTTP/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}