Skip to content

Commit

Permalink
[BUGFIX] Remove return {} on empty value in JSON encoding (FluidTYPO3…
Browse files Browse the repository at this point in the history
…#1487)

Allows false, null, empty arrays and raw values values on top level.
  • Loading branch information
maechler authored and NamelessCoder committed Jun 19, 2018
1 parent 382328e commit 4add271
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
3 changes: 0 additions & 3 deletions Classes/ViewHelpers/Format/Json/EncodeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
$preventRecursion = (boolean) $arguments['preventRecursion'];
$recursionMarker = $arguments['recursionMarker'];
$dateTimeFormat = $arguments['dateTimeFormat'];
if (true === empty($value)) {
return '{}';
}
static::$encounteredClasses = [];
$json = static::encodeValue($value, $useTraversableKeys, $preventRecursion, $recursionMarker, $dateTimeFormat);
return $json;
Expand Down
44 changes: 42 additions & 2 deletions Tests/Unit/ViewHelpers/Format/Json/EncodeViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,49 @@ public function encodesTraversable()
/**
* @test
*/
public function returnsEmptyJsonObjectForEmptyArguments()
public function returnsEmptyObjectOnTopLevel()
{
$this->assertEquals('{}', $this->executeViewHelper([]));
$this->assertEquals('{}', $this->executeViewHelper(['value' => new \stdClass()]));
}

/**
* @test
*/
public function returnsEmptyArrayOnTopLevel()
{
$this->assertEquals('[]', $this->executeViewHelper(['value' => []]));
}

/**
* @test
*/
public function returnsFalseOnTopLevel()
{
$this->assertEquals('false', $this->executeViewHelper(['value' => false]));
}

/**
* @test
*/
public function returnsTrueOnTopLevel()
{
$this->assertEquals('true', $this->executeViewHelper(['value' => true]));
}

/**
* @test
*/
public function returnsNumberOnTopLevel()
{
$this->assertEquals('1.0', $this->executeViewHelper(['value' => 1.0]));
}

/**
* @test
*/
public function returnsNullOnTopLevel()
{
$this->assertEquals('null', $this->executeViewHelper(['value' => null]));
}

/**
Expand Down

0 comments on commit 4add271

Please sign in to comment.