Skip to content

Commit

Permalink
Merge pull request #14 from wing5wong/master
Browse files Browse the repository at this point in the history
fix value error when request payload is empty, but content type is xml
  • Loading branch information
mtownsend5512 authored Oct 21, 2024
2 parents 1387d35 + 65d5d22 commit 5ed7852
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Providers/RequestXmlServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function registerIsXml()
protected function registerXml()
{
Request::macro('xml', function () {
if (!$this->isXml()) {
if (!$this->isXml() || empty($this->getContent())) {
return [];
}
try {
Expand Down
8 changes: 8 additions & 0 deletions tests/RequestXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,12 @@ public function request_can_parse_xml_as_a_valid_array()
$request = $this->createDummyRequest(['CONTENT_TYPE' => 'application/xml'], $this->testXml);
$this->assertEquals($request->xml(), $this->testArray);
}

/** @test */
public function request_with_xml_content_type_and_empty_payload()
{
$request = $this->createDummyRequest(['CONTENT_TYPE' => 'application/xml']);
$this->assertEquals($request->xml(), []);
$this->assertTrue($request->isXml());
}
}

0 comments on commit 5ed7852

Please sign in to comment.