Skip to content

Commit

Permalink
[BUGFIX] Trim whitespaces in JSON decode helper (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-pietka authored Jun 9, 2023
1 parent b1d4b0b commit 80a8696
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Classes/ViewHelpers/Format/Json/DecodeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public function render()
$json = $this->arguments['json'];
if ($json === null) {
$json = $this->renderChildren();
if ($json !== null) {
$json = trim($json);
}
if (empty($json)) {
return null;
}
Expand Down
28 changes: 28 additions & 0 deletions Tests/Unit/ViewHelpers/Format/Json/DecodeViewHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the "headless" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FriendsOfTYPO3\Headless\Tests\Unit\ViewHelpers\Format\Json;

use FriendsOfTYPO3\Headless\ViewHelpers\Format\Json\DecodeViewHelper;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

class DecodeViewHelperTest extends UnitTestCase
{
public function testRender(): void
{
$GLOBALS['TYPO3_CONF_VARS']['FE']['debug'] = true;
$decodeViewHelper = new DecodeViewHelper();
$decodeViewHelper->setArguments(['json' => null]);
$decodeViewHelper->setRenderChildrenClosure(function () { return "\n \n"; });
$result = $decodeViewHelper->render();
self::assertNull($result);
}
}

0 comments on commit 80a8696

Please sign in to comment.