Skip to content

Commit

Permalink
Merge branch '2.x'
Browse files Browse the repository at this point in the history
* 2.x:
  do not iterate non-array data
  • Loading branch information
xabbuh committed Mar 27, 2020
2 parents f3460d5 + 8857ef9 commit e287a8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Decoder/JsonToFormDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private function xWwwFormEncodedLike(array &$data): void
public function decode(string $data)
{
$decodedData = @json_decode($data, true);
if ($decodedData) {
if (is_array($decodedData)) {
$this->xWwwFormEncodedLike($decodedData);
}

Expand Down
8 changes: 8 additions & 0 deletions Tests/Decoder/JsonToFormDecoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ public function testDecodeWithRemovingFalseData()
$this->assertEquals('3.14', $decoded['floatKey']);
$this->assertEquals('bar', $decoded['stringKey']);
}

public function testDecodeStringData()
{
$decoder = new JsonToFormDecoder();
$decoded = $decoder->decode('"foo"');

$this->assertSame('foo', $decoded);
}
}

0 comments on commit e287a8e

Please sign in to comment.