Skip to content

Commit 8180b35

Browse files
committed
do not iterate non-array data
1 parent d6db30a commit 8180b35

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Decoder/JsonToFormDecoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private function xWwwFormEncodedLike(&$data)
4848
public function decode($data)
4949
{
5050
$decodedData = @json_decode($data, true);
51-
if ($decodedData) {
51+
if (is_array($decodedData)) {
5252
$this->xWwwFormEncodedLike($decodedData);
5353
}
5454

Tests/Decoder/JsonToFormDecoderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ public function testDecodeWithRemovingFalseData()
4747
$this->assertEquals('3.14', $decoded['floatKey']);
4848
$this->assertEquals('bar', $decoded['stringKey']);
4949
}
50+
51+
public function testDecodeStringData()
52+
{
53+
$decoder = new JsonToFormDecoder();
54+
$decoded = $decoder->decode('"foo"');
55+
56+
$this->assertSame('foo', $decoded);
57+
}
5058
}

0 commit comments

Comments
 (0)